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

1 Like

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

1 Like