James Hobson Posted March 31, 2017 Share Posted March 31, 2017 Hi all Is it possible to link applescript modules together so their variables pass from one to another? For example in the attached image - the central script module sets-up some variables which are then dealt with differently in the end-of-chain script modules. I've tried using {var:varname} to pass-through but it's not working... Is this actually possible? Here's an example workflow: https://www.dropbox.com/s/j52zibfpui9z0p7/multi-ascript.zip?dl=0 Cheers James Link to comment
deanishe Posted March 31, 2017 Share Posted March 31, 2017 (edited) Hi there, I've moved this to the proper forum. The Discussion & Help forum is for general Alfred usage. This forum is the right place for questions related to creating workflow. You should start by reading the stickied post on workflow variables. I'm afraid they don't work that way. There are no {var:...} expansions in Run Script elements. You have to use environment variables, e.g. set myVar to (system attribute "MY_VARIABLE") Your workflow also doesn't actually set any variables. Your central Run Script element (the one selected in your screenshot) is never run. It isn't connected to any kind of trigger or keyword. In order to set variables, you also have to return JSON or XML to Alfred, which isn't super easy in AppleScript. Perhaps better to combine the script with an Args and Vars utility to set the variable from {query}, so you can simply return the variable value from your AppleScript instead of trying to generate XML/JSON. Edited March 31, 2017 by deanishe Link to comment
James Hobson Posted April 1, 2017 Author Share Posted April 1, 2017 (edited) @deanishe Cheers for the reply, sorry I posted in the wrong forum. I think I'll go with your suggestion and use a query argument - sounds a lot simpler! Thanks for sharing your knowledge. Edited April 1, 2017 by James Hobson Link to comment
deanishe Posted April 1, 2017 Share Posted April 1, 2017 (edited) What are you building? Also, you can get away with creating your own JSON/XML in AppleScript easily enough as long as your variables are simple. Edited April 1, 2017 by deanishe Link to comment
James Hobson Posted April 3, 2017 Author Share Posted April 3, 2017 @deanishe It's for a small utility I've written to open a group of websites in one hit. I wanted to separate the AS vars (URLs) from the unique logic for each browser. A little lame (but useful). I'll take a look into using JSON when I have some spare time. Cheers Link to comment
deanishe Posted April 3, 2017 Share Posted April 3, 2017 (edited) Unless you need to open the URLs in a specific way, you don't need to use AppleScript to talk to different browsers. You can just use the open command with a URL: # open in default browser open https://www.google.com # open in Safari open -a Safari https://www.google.com # open in Chrome open -a "Google Chrome" https://www.google.com If that would work for you, then you wouldn't need to use the crazy language that is AppleScript. Opening a fixed series of URLs can be as simple as this. Edited April 3, 2017 by deanishe I meant that other crazy language Link to comment
James Hobson Posted April 3, 2017 Author Share Posted April 3, 2017 @deanishe Yeah - what I want is to open certain sites on set days of week or month. Then I can run the action daily and keep track of sites I read etc.. The `copy` command was a fluke find. Works well for this. This is how I've done it: set thisDay to weekday of (current date) as string set thisDate to day of (current date) set sites to {} -- Monday -- if thisDay is "Monday" then copy "https://throttlehq.com/home" to the end of sites end if -- Tuesday -- if thisDay is "Tuesday" then copy "http://twodollartues.com" to the end of sites end if -- 1st of each month -- if thisDate is 1 then copy "http://macappdeals.com" to the end of sites end if -- Everyday -- copy "http://macupdate.com" to the end of sites tell application "Firefox" activate repeat with site in sites do shell script "/usr/bin/open -a Firefox.app " & site end repeat end tell Link to comment
deanishe Posted April 3, 2017 Share Posted April 3, 2017 Got you. One observation: your do shell script line is technically incorrect. It should be do shell script "/usr/bin/open -a Firefox.app " & (quoted form of site) Because you're passing the URL to a shell, if it contains any characters with special meaning in a shell ("&" is a common one in URLs), you need to quote the URL or the shell will misinterpret it. As a rule, any variable you pass to do shell script should use (quoted form of theVariable), as it's liable to die in flames otherwise. Link to comment
James Hobson Posted April 4, 2017 Author Share Posted April 4, 2017 @deanishe Ah, OK gotcha. Cheers for that! 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