a-shell icon indicating copy to clipboard operation
a-shell copied to clipboard

Bookmarks aren't accessible from within Shortcuts

Open frkd-dev opened this issue 2 years ago • 4 comments
trafficstars

Hello,

I see similar reports here regarding paths while running a-shell from Shortcuts but I didn't find anything that would help me there.

Here is a quote from README:

Shortcuts can be executed either "In Extension" or "In App". … Both kind of shortcuts run by default in the same specific directory, $SHORTCUTS or ~shortcuts. Of course, since you can run the commands cd and jump in a shortcut, you can pretty much go anywhere.

Basically, cd is not working for me when I use bookmarks with the "in-extension" option.

image

When I'm doing cd ~/Library a-shell changes to a directory that has no Python packages or something that I see from within the app. Thus running commands like ~/Library/bin/myapp or ~home/Library/bin/myapp in Shortcuts end with an error myapp: command not found.

Strictly speaking "in-extension" mode appears unusable because I cannot reach the app's files somehow.

Am I doing something wrong?

frkd-dev avatar May 31 '23 16:05 frkd-dev

The "in-extension" and the app are two different apps from Apple's point of view. Therefore, they have a different home directory (~). cd ~/Library, when running in-extension, takes you to the Library folder of the home directory of the in-extension app, which is different from the Library folder of the home directory of the main app. Because file permissions are very restrictive on iOS, the extension cannot access the app directory, and the app cannot access the extension directory.

~shortcuts is shared between the apps, so you can access it from both apps. Python is using ~shortcuts/Library as a base directory when running in-extension, so you can add packages by copying them to ~shortcuts/Library/lib/python3.11/site-packages/....

Keep in mind that shortcuts running in-extension have a time limit of 5 seconds (enforced by the system). Many python scripts (including pip) take more than 5 seconds to finish.

holzschu avatar May 31 '23 16:05 holzschu

Thank you for the detailed reply. I believe such valuable info would be better to put in README rather than explain it to every random person coming to the bug tracker with such and similar questions.

I moved bin, lib, and share folders to $SHORTCUTS/Library and symlinked them from within the app's ~/Library folder and this worked.

Issue 2 After I moved bin, lib, and share folders to ~shortcuts/Library I was enabled to run Python scripts from Shortcuts as "in-extension". Some Python scripts are running fine but "yt-dlp" is failing immediately with "There was a problem communicating with the app". It's clearly not the "5 seconds" limit as the error popups immediately once the shortcut is executed.

image

Issue 3 The $PATH env variable contains $SHORTCUTS/Library/bin path but for some reason, scripts located in this folder cannot be run.

image

Sure, I can run my script with a full path $SHORTCUTS/Library/bin/dl but I'm trying to understand why the $PATH variable isn't respected.

Any thoughts on that?

frkd-dev avatar Jun 01 '23 07:06 frkd-dev

The first one is likely related to a recently identified issue with the position of cacert.pem. It will be fixed in the next version but in the meantime it can be fixed by setting the environment variable SSL_CERT_FILE to $APPDIR/cacert.pem, or copying cacert.pem to the location currently pointed by SSL_CERT_FILE.

The second one is more confusing. It shouldn't happen. I ran some tests, and it doesn't happen on my machine. One possibility is that dl is found, but it calls a command that is not found (e.g. it starts with #! commandNotFound).

holzschu avatar Jun 03 '23 08:06 holzschu

The "command not found" error was caused by a typo in "#!" line, thank you for pointing this out. Typing on the iPhone is painful and full of typos. 😒

Regarding the "problem communicating" issue. It looks like "yt-dlp" is causing this error somehow when it's running from Shortcuts and setting SSL_CERT_FILE doesn't help.

Also, I did run env without setting SSL_CERT_FILE, and it has shown it among other env vars and it was set to the app's pem certificate: /private/var/containers/Bundle/Application/A353ED73-7E42-4DE3-B123-ECB69A18F7DC/a-Shell-mini.app/Library/cacert.pem.

frkd-dev avatar Jun 09 '23 16:06 frkd-dev