I want to open a file with the Open File action using the file’s path. This doesn’t work because the shortcut sees the path as text not a file. How can I convert a path to a file object that the Open File action will open?
Another solution is to specify the files in the shortcut, or to get them with a dialog, but this is not a solution because I am storing the file paths in a text file.
Thanks for your post. I think it is possible in better way
You can use run AppleScript with his POSIX objet. Here’s another way, using only actions. This method does not take into account whether or not the slash / appears at the beginning of the file path like “/Users/iUser/Desktop/thefiletosee.rtf”
In the get file from at action, Two fields must be filled in. The first is the main folder (the root folder you select), the second is path to file (as string).
If no error, the output is the file object. The file is now available for display (open file) or processing by another program. This folder is independent of the computer where the shortcut is used. On your configuration, you will see the name of your root disk.
see screenshot
ximcsc. Thanks for the suggestion, which I appreciate, but I’m confused. In your screenshot where does M4HD250G come from?
I thought M4HD250G was my root folder, but that resulted in an error message (see screenshot below). What am I doing wrong? I’m running public beta 6 of macOS Tahoe. Perhaps that’s the issue.
Thank you for your insightful comments.
I usually rename the root disk.
In the screenshot, it is the name of my root disk (as visible in Finder Sequoia). In an older imac, it is another name (SSD_190G) (Ventura). Shortcuts app is shared via local network…
In the M4 - Shortcuts has “System settings - full disk access” - In the iMac - no…and the result are the same. Perhaps Tahoe needs new privacy settings …?
M.
You cannot go from a text file path to a file handle necessary for opening the document until you create a file handle that can be used in the Open File action.
I wrote a brief Shortcut to do just that which I insert between your two actions. I named it FileURL from Text Path:
Thanks ximcsc. I just upgraded to Tahoe RC1, and I still have the issue noted above. I had previously given the Shortcuts app, Shortcuts Events, and ShortcutsActions permissions in both the Accessibility and Full Disk Access panes of Privacy & Security. So, I guess Apple just isn’t going to allow this on Tahoe.
And with “root” if the file path has or doesn’t have a / at the beginning?
I discovered the existence of “root” when, as input, I had the result of the previous AppleScript including a line return POSIX file “//” (and not “/”)…
I’ll run some tests with Tahoe in a few weeks on a “cautious” test drive.
ximcsc. I tested the shortcut step-by-step increasing the Folder parameter by one level and decreasing the Path parameter by one level. The shortcut worked when the Folder parameter was my user name (i.e. robert) and the path parameter was /Desktop/Test.txt. Setting the Folder parameter to the Users folder didn’t work, and it didn’t make any difference if the Path parameter was or was not preceded by a slash. I also tested if running the shortcut by way of Spotlight Search might make a difference but it didn’t.
VikingOSX. Thanks for the suggestion which does the job. My only reservation is that no matter how simple the task, the Run AppleScript action takes about 260 milliseconds to run.
Just as a general comment on this topic, the original question I raise in this thread is perhaps not a good one. It’s a simple matter to set one or more folders using a File action at the beginning of a shortcut. Also, the Shortcuts app includes the ability to prompt a user for a folder when the shortcut is first imported. The following is an example where the Test 2 shortcut is being imported:
The average length of a human eyeblink is 100 ms or .1 second. Without any timing harness, that is how long this Shortcut takes (near instantaneous) to open a PDF from my Shortcut solution on a 14-core M4 Mac Mini Pro running Sequoia v15.6.1.
Trust me when I state that I was not happy about an intermediary AppleScript-based Shortcut in the solution.
My decision was mostly based on your reluctance for a file chooser solution if a list of paths were alreaady in a text file.
Google AI makes mistakes. Everyone including Google is aware of this.
I searched Google AI on something other than the specific topic of this thread, and the provided answer was based on this thread. Unfortunately, most of the provided answer was incorrect. As mentioned, this is not a surprise, but I found it interesting as a simple example in how Google AI gets stuff wrong. BTW, Google AI does return a lot of helpful and accurate information about shortcuts, and I use it often.
Thank you for your feedback. For my part, I have continued testing (on Sequoia) to evaluate the limitations and flaws of this “Get File” action and its two fields “from” and “at path”. I have recorded my observations, as if in a lab notebook, on the /dev-xiligroup/ repository on the Github site. I hope you find it useful. (At least one more week and testing on Tahoe can begin!)