jemostrom Posted April 14, 2013 Share Posted April 14, 2013 Newbie here, I'm afraid I haven't really understood how data is passed between Alfred and scripts. Could anyone please explain how it's done? I'm mostly interested in Applescript and Python (although I assume that all scripting languages works the same). - jem Link to comment
jdfwarrior Posted April 14, 2013 Share Posted April 14, 2013 Newbie here, I'm afraid I haven't really understood how data is passed between Alfred and scripts. Could anyone please explain how it's done? I'm mostly interested in Applescript and Python (although I assume that all scripting languages works the same). - jem Alfred passes data to script in the form of a placeholder variable, {query}. So, when passing data into a Run Script item with the language set to Python, you could do something simple like: temp = "{query}" print temp Which (obviously) would take the value passed into the workflow, save it into a variable named "temp" and then print that value. You can test this by creating a keyword, run script, and a large type item, tie them together, and insert the code above. Anything entered after the workflow keyword would be displayed in Large Type. The only exception to this would be the Run NSAppleScript item. NSAppleScript items differ from /usr/bin/osascript Run Script based items in, NSAppleScript items will block Alfred from doing anything else until the execution of the script completes. A Run Script item with the language set to osascript runs in the background. To use a Run NSAppleScript, you wrap your code in on alfred_script(q), similar to Alfred 1. See example below. on alfred_script(q) set temp to q return temp end alfred_script Let me know if you have any other questions. Link to comment
zkarj Posted May 11, 2013 Share Posted May 11, 2013 Let me know if you have any other questions. Thanks! I've been looking for this simple explanation for ages. Nicely written. I've now got my workflow up and running sweetly. I will post it soon, but there's one related question I have. My workflow's embedded AppleScript contains a couple of variables that users will have to customise for their own purposes – is there a smart way to do that? Some way of prompting the user once at install and thereafter just working with the entered values. Link to comment
Carlos-Sz Posted May 11, 2013 Share Posted May 11, 2013 Thanks! I've been looking for this simple explanation for ages. Nicely written. I've now got my workflow up and running sweetly. I will post it soon, but there's one related question I have. My workflow's embedded AppleScript contains a couple of variables that users will have to customise for their own purposes – is there a smart way to do that? Some way of prompting the user once at install and thereafter just working with the entered values. I write my workflows in AppleScript too. Check this workflow: http://www.alfredforum.com/topic/460-to-dropbox-30-formerly-move-to-dropbox-url-to-the-clipboard/ Or this working in progress with a more updated approach regarding a setup: download now Link to comment
zkarj Posted May 13, 2013 Share Posted May 13, 2013 I write my workflows in AppleScript too. Check this workflow: http://www.alfredforum.com/topic/460-to-dropbox-30-formerly-move-to-dropbox-url-to-the-clipboard/ Or this working in progress with a more updated approach regarding a setup: download now Thanks, but I'm finding that hard to follow without a basic explanation of the technique. Link to comment
adayzdone Posted May 13, 2013 Share Posted May 13, 2013 Thanks, but I'm finding that hard to follow without a basic explanation of the technique. I have posted an example of how to Generate Feedback in Alfred 2 Workflows . From the Script Filter you can call the AppleScript with: osascript xml.scpt "{query}" To accept the query in the AppleScript, use: on run argv set query to argv as text end run Note that argv is a list and may cause problems if you don't convert it to text first. Link to comment
Carlos-Sz Posted May 13, 2013 Share Posted May 13, 2013 Thanks, but I'm finding that hard to follow without a basic explanation of the technique. Here is a simple workflow sample that is shorter and commented: download now Start reading tm_filter.scpt then tm_time.scpt Link to comment
adayzdone Posted May 13, 2013 Share Posted May 13, 2013 Hi Carlos, You can reduce this set wf to load script POSIX file (POSIX path of ((POSIX file ((POSIX path of (path to me)) & "/..") as text) & "q_workflow.scpt" as text) as text) to this... set wf to load script POSIX file (POSIX path of ((path to me as text) & "::") & "q_workflow.scpt") Carlos-Sz 1 Link to comment
Carlos-Sz Posted May 13, 2013 Share Posted May 13, 2013 Hi Carlos, You can reduce this set wf to load script POSIX file (POSIX path of ((POSIX file ((POSIX path of (path to me)) & "/..") as text) & "q_workflow.scpt" as text) as text) to this... set wf to load script POSIX file (POSIX path of ((path to me as text) & "::") & "q_workflow.scpt") Thank you. I’ll try it for sure. 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