Jump to content

Run script/osascript will not run as action from File Filter


Recommended Posts

Does anyone have idea why a Run Script action (/usr/bin/osascript) will not execute from a File Filter trigger? I could swear this was working earlier.

 

Trying to override the search in spotlight function with an applescript to parse the filename to a more usable form.

 

Applescript runs fine as standalone or if triggered by keyword in the workflow. Copying the applescript to a NSAppleScript action (triggered by the File Filter) works as well, but I prefer an embedded script.

 

I'm using the same Run script I've used in other workflows (and it works if triggered by a keyword in this workflow):

run script (POSIX file ((do shell script "pwd") & "/find-in-spotlight.scpt")) with parameters {"{query}"}

Yet no matter how I link it to the File Filter it doesn't execute.

Link to comment

Does anyone have idea why a Run Script action (/usr/bin/osascript) will not execute from a File Filter trigger? I could swear this was working earlier.

 

Trying to override the search in spotlight function with an applescript to parse the filename to a more usable form.

 

Applescript runs fine as standalone or if triggered by keyword in the workflow. Copying the applescript to a NSAppleScript action (triggered by the File Filter) works as well, but I prefer an embedded script.

 

I'm using the same Run script I've used in other workflows (and it works if triggered by a keyword in this workflow):

run script (POSIX file ((do shell script "pwd") & "/find-in-spotlight.scpt")) with parameters {"{query}"}

Yet no matter how I link it to the File Filter it doesn't execute.

 

This could be simplified a little.. Your script is using applescript to run a shell script that runs and applescript. Why not just copy the code from the .scpt file into Alfred for use in a Run Script or Run NSAppleScript? This would also make it so that you don't have to rely on file paths to the script being correct as well.

Link to comment

Does anyone have idea why a Run Script action (/usr/bin/osascript) will not execute from a File Filter trigger? I could swear this was working earlier.

 

Trying to override the search in spotlight function with an applescript to parse the filename to a more usable form.

 

Applescript runs fine as standalone or if triggered by keyword in the workflow. Copying the applescript to a NSAppleScript action (triggered by the File Filter) works as well, but I prefer an embedded script.

 

I'm using the same Run script I've used in other workflows (and it works if triggered by a keyword in this workflow):

run script (POSIX file ((do shell script "pwd") & "/find-in-spotlight.scpt")) with parameters {"{query}"}

Yet no matter how I link it to the File Filter it doesn't execute.

 

It seems to be working here. Anyway, you can simplify the command e.g.:

run script "unidentified.scpt" with parameters {"{query}"}
Link to comment

This could be simplified a little.. Your script is using applescript to run a shell script that runs and applescript. Why not just copy the code from the .scpt file into Alfred for use in a Run Script or Run NSAppleScript? This would also make it so that you don't have to rely on file paths to the script being correct as well.

 

Thanks for the feedback, but that's what I'm currently doing to make it work: "Copying the applescript to a NSAppleScript action (triggered by the File Filter) works as well"

 

I'd like to understand why this isn't working. Additionally,  I have to edit and debug n Script Editor; then copy to NSApplescript action. Alfred NSApplescripts are also limited, e.g. cannot have subroutines/functions. So I prefer to use embedded scripts.

 

What's confusing is that this exact setup works in other workflows for me. I remember it working here for a while triggered by File Filters.

 

I've tested:

 

File Filter → large type (works for passed query)

File Filter → open file (works for passed query)

Keyword→ Run script quoted above (works for passed query)

 

but File Filter → Run script quoted above (fails). Doesn't even trigger the script as the first script statement is a test notification.

Link to comment

 

It seems to be working here. Anyway, you can simplify the command e.g.:

run script "unidentified.scpt" with parameters {"{query}"}

Thanks for the feedback, but the new code only works when triggered by a keyword and fails to trigger from File Filter (same as original posted code).

Link to comment

Thanks Carlos, but I found the issue. Long story short: I had the defaults (all) for escaping and the escaped path string was stopping the script from executing. Unchecking the escape options made the workflow work as intended.

 

Long version: My keyword test input was only working because I had didn't use a real path with forward slashes, etc. When I used the copy clipboard test results from the File Filter as the input for the keyword (e.g. /Volumes/Data SSD/Downloads/!Sorted/!Icons/test icon-ai.zip), it failed as well. Again the first line of the script is a test notification, so I know the script never ran. My other workflows don't use file paths, so I never ran into this corner case. 

 

Again, I could work around it by using Run NSApplescript instead of an embedded script, but I wanted to understand what was failing. Maybe this will help someone else as well. 

 

 

Thanks again to everyone who responded.

Link to comment

Thanks Carlos, but I found the issue. Long story short: I had the defaults (all) for escaping and the escaped path string was stopping the script from executing. Unchecking the escape options made the workflow work as intended.

 

Long version: My keyword test input was only working because I had didn't use a real path with forward slashes, etc. When I used the copy clipboard test results from the File Filter as the input for the keyword (e.g. /Volumes/Data SSD/Downloads/!Sorted/!Icons/test icon-ai.zip), it failed as well. Again the first line of the script is a test notification, so I know the script never ran. My other workflows don't use file paths, so I never ran into this corner case. 

 

Again, I could work around it by using Run NSApplescript instead of an embedded script, but I wanted to understand what was failing. Maybe this will help someone else as well. 

 

 

Thanks again to everyone who responded.

 

Great. For AppleScript check Double Quotes and Backslashes.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...