Running macro on icloud folder returns no such file or directory?

Hi all,

I couldn't find any clue why the following would not work, hence I finally made the switch from being a silent reader and signed up… :wave:

I'm trying to run the following macro on my iA writer folder within icloud. When using it with a local or dropbox path everything works fine — if I use ~/Library/Mobile Documents/27N4MQEA55~pro~writer/Documents/ I get a "No such file or directory." error even though I can manually cd into the above directory and run the ls command. Do you guys have any hints or workaround?

cd ~/Dropbox/zettelkasten
ls -t | sed -e 's/.[^.]*$//'

which will be inserted into: 
[[%Variable%tmp%]]

In case anyone wonders: the macro is needed in conjunction with the archive to provide a typeahead functionality in order to link to notes more easily.

Thanks in advance for any hint :slight_smile:

Do the commands work in the Terminal? If you are in the Terminal and run the commands:

cd ~/Library/Mobile\ Documents/27N4MQEA55~pro~writer/Documents/
ls -l

What do you get?

Are you making sure to quote the space in Mobile Documents, and not quote the ~?

Thanks @peternlewis!

…it must have been the space in Mobile that caused trouble. I could have sworn I had checked it when trying but obviously must haved missed something. Now it works like a charm. Thanks again :slight_smile:

1 Like

I’m having similar problems with the exact same script.

Can you clarify exactly whether quotes need to be enclosing the path when there is a space in the path, within the KM script area?

I thought I had it working, but then grep ended up running away with my processor and bringing the machine down, so I must have something wrong.

The problem has only emerged with this script after I moved its operation out of a Dropbox folder and into an iCloud one.

Hey Andrew,

If you're running from an Execute a Shell Script action then spaces must either be quoted or escaped.

Quoted:

You can quote just the portion of the path that has spaces in it, but I tend to quote the whole path:

Regular Posix Path:

ls '/Applications/Applications_Chris/Audio Visual Apps'

Tilde-based path:

ls ~/'Library/Mobile Documents/'

ls ~/'Library/Mobile Documents/8HSTZV64A5~com~acqualia~soulver/Documents'

** Note that the ~/ prefix MUST NOT be contained in the quotes!   Because the shell will consider it a literal string and NOT expand it to the user's home directory.

Escaped:

ls ~/Library/Mobile\ Documents/

ls ~/Library/Mobile\ Documents/8HSTZV64A5~com~acqualia~soulver/Documents

See Shell Scripting for more info.

-Chris

2 Likes

Thanks for this excellent explanation. The script is working now with no runaway processes eating my CPU.

1 Like

Relatedly,

In the Finder calling the Go-To Folder (Command-Shift-G) and pasting:

/Users/bernshanfield/Library/Mobile Documents/com~apple~CloudDocs/Documents/E/Existence for Items/Not Now

Opens the location in a Finder window while pasting the same pathway from within a macro only goes to the /Users folder.

I’m running the macro in the Mail app.

Here’s the macro with the steps after the paste file path disabled.

Download: 37)􀢅Not Now.kmmacros (8.2 KB)

Strangely, I got this to work yesterday after a lot of trying and even put it into another macro with the same base file path and modifying the ending to go to another folder, and that worked leaving me to think I’d cracked the code.

No such results today. Today I’m back to the /Users folder.

Even stranger, this path:

/Users/bernshanfield/Library/Mobile Documents/com~apple~CloudDocs/Documents/R/Records Yearly/Records 2023/01 Jan Recs

Works from within a macro while

/Users/bernshanfield/Library/Mobile Documents/com~apple~CloudDocs/Documents/E/Existence for Items/Not Now

Does not. The second macro is just a duplicate of the first with the file path edited.

Ideas?

Hey Bern,

In general this sort of problem is a user error.

One of the paths you pasted into the forum had a leading space, and that or other extra spaces might cause a problem.

Try this version and note the various changes I've made:

37)􀢅Not Now.kmmacros (5.9 KB)

Macro Image

Keyboard Maestro Export

When you paste paths be very careful to not alter them – it's all to easy for your fingers to do the walking and introduce an error that's hard to see.

You can also drop strings into BBEdit and turn on “Show Invisibles” to see if there's anything weird going on.

-Chris

1 Like

Thanks Chris!

Some truly weird stuff going on.

I modified your macro to pause longer after inserting text into the Go To window and then a type Return as there is no Save button in my Go To dialog.

I then have a Pause until Save button step. Here's where it gets weird.

The sequence stops at the Go To window with the correct path pasted in. I've disabled all the following steps.

When I manually press the return key, the save dialog goes to the correct location BUT then pastes the path from the Insert Text step into the Save As field all by itself without any steps enabled in the macro sequence.

It's like there is some unseen buffer holding something and then activating on its own. There must be something being held that needs to be cleared.

With Monterey and Ventura, I have had strange things like this happen with ⇧⌘G Go To Folder, when pasting the path rather than typing the path.

So, here is my sequence of Actions to do this in Monterey and Ventura with the only real difference from what you are trying, being "typing" text rather than "pasting" text.

2 Likes

Damn if you aren't right, thank you! A Ventura :beetle:

2 Likes