Jump to content

Trouble getting started with workflows using applescript


Recommended Posts

Posted

I've got the most basic of all newbie questions. I created an applescripts with about 200 lines  and it works fine when running it from the Applescript editor. I bring it into an Alfred workflow and nothing happens. I was able to get it to work with NSAppleScript but I want it to run in the background so I'm using the action RunScript. 

 
I've created a very simple one line script and I can't get that to work with RunScript. I'm missing something fundamental here but I've been racking my brain for a week and I see no one in the forum is asking such a basic question. I see a bunch of workflows that start out with "run script (POSIX file…" but I've got to believe I can just drop my applescript into the script text box of a Run Script. 
 
Here's a simple test I did. Can you tell me what I'm doing wrong?
 
1) In Alfred workflow I create a new Keyword to Scrip workflow, which gives me a Keyword box and a Run Script box already connected. I right click on the new workflow and choose "Edit Details" where I name the workflow "Test01"
2) I open the Keyword box, enter Test01 for the keyword, check "with space" and choose "Argument Optional", then hit the save button. (I've also tried No Argument for this test -- no difference in the results)
3) I open the RunScript box, select language "/usr/bin/osascript", Check only "Double Quotes" and "Backslashes" and enter the following line  in the Script field:
display dialog "Test01 script running" then hit the save button.
 
At this point it seems like I'm done. I bring up Alfred, type Test01 (Alfred recognizes it as a workflow), I hit return and absolutely nothing happens. 
 
Any help would be greatly appreciated. 

 

Posted

 

I've got the most basic of all newbie questions. I created an applescripts with about 200 lines  and it works fine when running it from the Applescript editor. I bring it into an Alfred workflow and nothing happens. I was able to get it to work with NSAppleScript but I want it to run in the background so I'm using the action RunScript. 

 
I've created a very simple one line script and I can't get that to work with RunScript. I'm missing something fundamental here but I've been racking my brain for a week and I see no one in the forum is asking such a basic question. I see a bunch of workflows that start out with "run script (POSIX file…" but I've got to believe I can just drop my applescript into the script text box of a Run Script. 
 
Here's a simple test I did. Can you tell me what I'm doing wrong?
 
1) In Alfred workflow I create a new Keyword to Scrip workflow, which gives me a Keyword box and a Run Script box already connected. I right click on the new workflow and choose "Edit Details" where I name the workflow "Test01"
2) I open the Keyword box, enter Test01 for the keyword, check "with space" and choose "Argument Optional", then hit the save button. (I've also tried No Argument for this test -- no difference in the results)
3) I open the RunScript box, select language "/usr/bin/osascript", Check only "Double Quotes" and "Backslashes" and enter the following line  in the Script field:
display dialog "Test01 script running" then hit the save button.
 
At this point it seems like I'm done. I bring up Alfred, type Test01 (Alfred recognizes it as a workflow), I hit return and absolutely nothing happens. 
 
Any help would be greatly appreciated. 

 

 

It certainly sounds as if you are setting it up correctly but just to make sure that you aren't missing a step, I created a workflow that does exactly what you are asking for, just displaying a dialog. If you would, please download it here and let me know if it works correctly. The keyword to this workflow is 'sample01'. Please report back with your results.

Posted

David,

 

Thanks for the quick response. I downloaded and installed your workflow, sample01. The same problem--absolutely nothing happens (all windows were minimized before running the workflow--it wan't hidden behind something). I assume the display dialog appeared on your computer. I can run scripts from terminal (with the permissions set correctly) and from the Applescript Editor. My full-up script runs from a Run NSAppleScript Action box. It's all rather frustrating.

Posted

David,

 

Thanks for the quick response. I downloaded and installed your workflow, sample01. The same problem--absolutely nothing happens (all windows were minimized before running the workflow--it wan't hidden behind something). I assume the display dialog appeared on your computer. I can run scripts from terminal (with the permissions set correctly) and from the Applescript Editor. My full-up script runs from a Run NSAppleScript Action box. It's all rather frustrating.

 

Strange. Yeah it worked fine on my machine. Could you take a look at Console.app and try the workflow again and see if you are getting any kind of errors when you are attempting to run this workflow?

Posted

Yeah, Console.app shows no messages for Test01 or Sample01. I put an error in a workflow I downloaded (uses Run NSApplescript) just to see what kind of message I'd get. The message clearly states "Alfred 2" and the workflow name. So I'm sure the scripts aren't generating an error. I was chasing down an idea earlier; I think something in my setup doesn't allow third party apps to run applescript. There is a Run Applescript service available to some apps, like Notes. I added an applescript display dialog command into a Note, selected it and ran the service. I get an OS X message: Confirm Service: Notes wants to use the restricted Service "Run as Applescript" with buttons "Run Service" and "Cancel".   Selecting "Run Service" opens Applescript and bounces the icon on the dock, it doesn't take focus. After clicking on the bouncing Applescript icon the dialog appears. 

Posted

Yeah, Console.app shows no messages for Test01 or Sample01. I put an error in a workflow I downloaded (uses Run NSApplescript) just to see what kind of message I'd get. The message clearly states "Alfred 2" and the workflow name. So I'm sure the scripts aren't generating an error. I was chasing down an idea earlier; I think something in my setup doesn't allow third party apps to run applescript. There is a Run Applescript service available to some apps, like Notes. I added an applescript display dialog command into a Note, selected it and ran the service. I get an OS X message: Confirm Service: Notes wants to use the restricted Service "Run as Applescript" with buttons "Run Service" and "Cancel".   Selecting "Run Service" opens Applescript and bounces the icon on the dock, it doesn't take focus. After clicking on the bouncing Applescript icon the dialog appears. 

 

What OS are you using? I don't remember what all you get prompted for in Mavericks but I know that there are several things you have to give Alfred access to for things to work properly in Mavericks.

Posted

Mac OS X 10.8.4, the latest release (non-Beta). I have a MacBookPro, also with 10.8.4. Let me dig that out and test these workflows there. I'll let you know.

Posted

My laptop, also running OS X 10.8.4 behaves the same way. So that probably eliminates a quirky installation of Alfred 2, since they were done totally independent of each other at different times. (What's the likelihood of two bad installations of Alfred 2?)

 

I should add that I'm running the latest version of Alfred 2, and of course I have the PowerPack.

Posted (edited)

I just tried David's script.  It doesn't work for me either, but I get the following message in system.log : 

 

Jun 26 10:52:05 mycomputernamehere.local osascript[7485]: Performance: Please update this scripting addition to supply a value for ThreadSafe for each event handler: "/Library/ScriptingAdditions/Satimage.osax"

 

Then I updated satimage (here : http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html )

 

and now it still fails, but without any message in the log.

Edited by dfay
Posted

Having the same issue here. The error message is:

 

/tmp/test.osa:0:71: execution error: No user interaction allowed. (-1713)

 

If I change David's script like this, it works:

 

tell application "System Events"
    activate
    display dialog "This is a sample Applescript dialog called from Alfred"
end tell

Posted

Froethen,

 

Thanks! It works for me too. I had just about given up on creating Alfred workflows with Applescript.  I've got my 100-line Caffeine workflow working now. Do you have any idea why you and I need to tell application "System Events" to display dialog while David and others can just use the display dialog without wrapping it around a tell statement? 

Posted

Froethen,

 

Thanks! It works for me too. I had just about given up on creating Alfred workflows with Applescript.  I've got my 100-line Caffeine workflow working now. Do you have any idea why you and I need to tell application "System Events" to display dialog while David and others can just use the display dialog without wrapping it around a tell statement? 

 

I think it may be something to do with me using Mavericks. *hangs head* I didn't even think about that. I just tried the same workflow on a Mountain Lion machine of mine and I got nothing as well. Works perfectly in Mavericks though. So.. looks like we have a temporary fix but, gives you something to look forward to with Mavericks? :)

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