Jump to content

Help with Applescript


Recommended Posts

I have a workflow that works fine with NSApplescript however I prefer to run scripts in the background with /usr/bin/oascript.  I often have difficulty passion the arguments to Alfred with oascript.  Here is a section of a workflow that I cannot get to work with oascript.  I have tried all types of escape sequences but none work.  The script runs find in AS editor.

 

on alfred_script(q)
 tell application "Terminal"
  do script q in selected tab of the front window
 end tell
end alfred_script
 
 
tell application "Terminal"
 do script "{query}" in selected tab of the front window
end tell

 

Link to comment

Maybe I was not clear I have no problem getting this to work in NSAppleScript the problem is getting the code to run in /usr/bin/oascript.  The following code does not run work in oascript.  

 

tell application "Terminal"

 do script "{query}" in selected tab of the front window
end tell
Link to comment

I have a workflow that works fine with NSApplescript however I prefer to run scripts in the background with /usr/bin/oascript.  I often have difficulty passion the arguments to Alfred with oascript.  Here is a section of a workflow that I cannot get to work with oascript.  I have tried all types of escape sequences but none work.  The script runs find in AS editor.


 


This code runs fine in NSApplescript


on alfred_script(q)

 tell application "Terminal"

  do script q in selected tab of the front window

 end tell

end alfred_script

 

This code does not work in oascript


tell application "Terminal"

 do script "{query}" in selected tab of the front window

end tell


 


Link to comment

 

I have a workflow that works fine with NSApplescript however I prefer to run scripts in the background with /usr/bin/oascript.  I often have difficulty passion the arguments to Alfred with oascript.  Here is a section of a workflow that I cannot get to work with oascript.  I have tried all types of escape sequences but none work.  The script runs find in AS editor.

 

This code runs fine in NSApplescript

on alfred_script(q)
 tell application "Terminal"
  do script q in selected tab of the front window
 end tell
end alfred_script
 
This code does not work in oascript
tell application "Terminal"
 do script "{query}" in selected tab of the front window
end tell

 

 

 

[merged in duplicate topic]

 

Could you post your workflow using osascript as this should work as expected.

 

Agreed. I created a temporary workflow and pasted your code it and it works just as expected. Perhaps there is a simple setting/configuration item that needs to be tweaked to get this to work the way you want. If you could post the workflow, I could take a look at it and let you know.

Link to comment
  • 2 weeks later...

Here is the workflow with both the NSApplescript and Oascript.

 

https://db.tt/G4Ub8SeJ

 

Found the issue pretty quick. The run NSApplescript doesn't have all the escaping options that Run Script does so, when you passed the text to the Run Script item, all the escaping options were still enabled and the text passed into it was being escaped. Think about it like this..

 

If you typed: "cmd pwd"

 

NSAppleScript got: cmd pwd

Run Script got: cmd\ pwd

 

It escaped the space in the input. Obviously this would cause an issue. If you turn off the escaping options in the Run Script item, it should work fine.

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...