How to import/export files with shortcuts?
Hi, I’m new to a-Shell and am currently having trouble transferring files in and out of the app using shortcuts.
For exporting a file out I’m using the a-Shell ‘Get File’ action, followed by Apple’s Save File action. However this results in an error saying the file could not be found.
For importing a file into a-shell I’m using the Apple Get File action followed by the a-Shell ‘Put File’ action. This completes without error, however I don’t see the file in a-Shell when doing an ‘ls’.
What am I doing wrong?
Also, I think it would be great if there was some in-depth documentation explaining how to get a-Shell specific tasks completed.
Thanks!
Hi,
The short answer is: Shortcuts are running in their own directory, $SHORTCUTS. So, from the App or from the File explorer, you are not seeing the same files. The solution is to move files to and from this directory, or to start the Shortcut with a cd ~/Documents/ command.
The long answer is that Shortcuts running "In Extension" and Shortcuts running "In App" are, from Apple's point of view, two different applications, with two different ~ directories. $SHORTCUTS is a middleground that they can both access. This also means that cd ~/Documents/ will move you to two different places depending on whether the shortcut is run in App or in Extension.
Thank you! Got it all sorted out with Importing/Exporting. After I did an import with Shortcuts, I did an “ls $SHORTCUTS” and saw the file.
Hi @holzschu I am having some issues with files and thought to write here for better documentation.
I am trying to do the following:
- User gives input in shortcuts
- The input is a number which is passed to Execute shell command
- The command is a simple Python script that accepts the input as a command line argument and processes it. In this case I am creating a trivial factorial program
- Next, I’d like the shortcut to display back the output from the Python program
Steps 1, 2, and 3 are easy.
I am running Step 2 (Execute shell command In the App) as Python does not run otherwise.
I am not sure how best to do step 4.
One option is to redirect the output of Python to a temporary text file, read the text file via Get File and then display the output in alert/quick look.
Other option would be to get stdout directly from the executed path.
I don’t have any clue about the latter.
Regarding the former, I am getting stuck. I am able to create the temp text file but unable to read it back in shortcuts.
The following is an image of the shortcut.

The following is the link to the shortcut: https://www.icloud.com/shortcuts/76a296293d3749cf9aab2b647734e437
The following is the content of factrial.py
import math
import sys
print(sys.argv)
num = int(sys.argv[1])
print(f"The factorial of {num} is {math.factorial(num)}")
My questions:
- What do I need to change in order to get temp.txt to be read in shortcuts app?
- Can we directly get stdout from executing shell command back to shortcuts?
I think you need to add "open shortcuts://" to the list of commands to get back to the Shortcuts app once all commands are executed in the a-Shell app. Once you're there, either "cat temp.txt" executed in extension or get File should work.
We get the stdout of all shell commands executed in Extension in shortcuts, but for commands executed in App (as all those that use Python), we need the "open Shortcuts://" to get back to Shortcuts.
Thanks @holzschu I got it to work :)
I wrote about it here: https://nipunbatra.github.io/blog/setup/2021/06/14/setup-ipad.html#shortcuts
Is there an easier way? Also, I had to add the delay of 1 second. Otherwise, sometimes it didn’t work for me as “temp.txt” would not be found.
I don't think there's an easier way. Shortcuts that run "in Extension" don't get access to the files in app main dir, so "open Shortcuts://" is the best way. You could probably wait in the app instead of in the shortcut, with "sleep 0.1" before "open Shortcuts://".
I use pbcopy and get the result back in the clipboard.
On Tue, Jun 15, 2021 at 6:13 AM Nicolas Holzschuch @.***> wrote:
I don't think there's an easier way. Shortcuts that run "in Extension" don't get access to the files in app main dir, so "open Shortcuts://" is the best way. You could probably wait in the app instead of in the shortcut, with "sleep 0.1" before "open Shortcuts://".
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/holzschu/a-shell/issues/74#issuecomment-861374029, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLDPSDDFPEM7EHDODJP5STTS4RUBANCNFSM4N4VWU7Q .
Thanks, this is super useful. I have modified my post to include the pbcopy based version too.
Post: https://nipunbatra.github.io/blog/setup/2021/06/14/setup-ipad.html#shortcuts
I am pasting the images here as well in case anyone wants to use
Using pbcopy
Using files
Example: https://www.icloud.com/shortcuts/f97c2001dfbe4e5e851442fc5015fe10
On Tue, Jun 15, 2021 at 7:57 AM Nipun Batra @.***> wrote:
Thanks, this is super useful. I have modified my post to include the pbcopy based version too.
Post: https://nipunbatra.github.io/blog/setup/2021/06/14/setup-ipad.html#shortcuts
I am pasting the images here as well in case anyone wants to use Using pbcopy
[image: Shortcut-2] https://user-images.githubusercontent.com/60985/122048299-b4954200-cdfe-11eb-897a-7372806ca5c1.png Using files
[image: Shortcut-Working] https://user-images.githubusercontent.com/60985/122048341-beb74080-cdfe-11eb-9fd2-ce3174581777.png
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/holzschu/a-shell/issues/74#issuecomment-861436358, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLDPSBBR5JLDTNRCERTUHTTS4523ANCNFSM4N4VWU7Q .
I feel as though I've been down this path before but how do I do a Get File from a Shortcut and get back a file that is in the apps directory?
Is there any chance of getting a shortcut command "wait for a-shell commands to finish"?
I'm using a-shell to run scripts that download files that take between seconds and minutes.
If I understood the question correctly, you can do that by launching a set of commands with Shortcuts: first, your download command, then "open shortcuts://" to go back to Shortcuts and continue the shortcut execution.