Hans-Pe Posted July 7, 2021 Share Posted July 7, 2021 I wrote a workflow which queries System Events for the currently active application. The result is used in a tell block to query the application for the path of the file corresponding to the top window. Finally this path is used to pop up Alfred's file action menue. Short Snippet to show the principle and describe my question: tell application activeApp set the_doc to front document set the_name to the name of the_doc set the_result to path of the_doc end tell When run outside Alfred, the snippet works as expected. But it throws AppleScript error -1728 when included inside Run NSAppleScript and Run Script (/usr/bin/osascript). The error is thrown at the third set command, that is, I am able to get the front document and its name property, but I fail to access the document's property path. -1728:„TextEdit“ hat einen Fehler erhalten: „path of document "alfred"“ kann nicht gelesen werden. Running the script from Sripteditor works fine. Running the compiled AppleScript with osascript from terminal also works fine. Running the AppleScript text with osascript (I think, this is how Alfred is doing it) from terminal yields -1728 as in the Alfred case. To make it work in a workflow, I have to compile the script with the help of Scripteditor and run the resulting scpt-file with osascript in a shell in Run Script: query=$1 echo -n $(osascript frontfile.scpt "$query") I provide two workflow-files on Github: frontmostdoc.alfredworkflow is the released and working workflow frontmostdoc-prototype.alfredworkflow shows how I started and demonstrates the issues describes above: keywords "wo" and "ou" are failing, keyword "where" works. Is there a bug in osascript or did I run into some kind of restriction in the AppleScript Language macOS BigSur Version 11.4 - Hans-Peter Link to comment
deanishe Posted July 7, 2021 Share Posted July 7, 2021 It's an AppleScript thing. That's clear enough from the fact that it only works if the script is compiled (Script Editor compiles scripts before running them). Also, don't use Run NSAppleScript: it behaves in weird ways, and it's run on Alfred's main thread, so Alfred will freeze while your script is running. The way you're doing it with the "where" keyword is the right way. Link to comment
Hans-Pe Posted July 8, 2021 Author Share Posted July 8, 2021 15 hours ago, deanishe said: It's an AppleScript thing. That's clear enough from the fact that it only works if the script is compiled (Script Editor compiles scripts before running them). Also, don't use Run NSAppleScript: it behaves in weird ways, and it's run on Alfred's main thread, so Alfred will freeze while your script is running. The way you're doing it with the "where" keyword is the right way. deanishe, you are right. It's an AppleScript thing. I compared the scpt-files produced with Scripteditor and with osacompile. Same length and they are nearly identical, they differ only in the event code used for property path of document: Scripteditor generates ppth, which is correct and osacompile generated FTPc, which is property path of class URL, I found a list of event codes in gist. You objected to my use of "Run NSAppleScript". OK, I merged the two AS now into a single "Run Script", this simplifies the whole workflow and makes it more efficient. Thanks for your comments -Hans-Peter Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now