Caleb Grove Posted October 17, 2014 Share Posted October 17, 2014 (edited) I've been playing around with the new JavaScript for Automation in Yosemite, and I must say that I've been smitten. It so much more predictable than AppleScript. However, I'm a noob when it comes to scripting in general. So, on that note, does anyone know how I should be implementing JavaScript into my Alfred workflows? It won't run in a NSAppleScript action, nor will it run if I put in in a Run Script action with the language set to osascript. I was able to get it to work if I placed the script inside the workflow folder and ran it with a bash command, but then how do I grab the arguments in the script? Thanks! Edited October 17, 2014 by Caleb Grove Link to comment
ctwise Posted October 17, 2014 Share Posted October 17, 2014 I've been playing around with the new JavaScript for Automation in Yosemite, and I must say that I've been smitten. It so much more predictable than AppleScript. However, I'm a noob when it comes to scripting in general. So, on that note, does anyone know how I should be implementing JavaScript into my Alfred workflows? It won't run in a NSAppleScript action, nor will it run if I put in in a Run Script action with the language set to osascript. I was able to get it to work if I placed the script inside the workflow folder and ran it with a bash command, but then how do I grab the arguments in the script? Thanks! Either wait for a new release that supports it or run it using the shell 'osascript' command. Caleb Grove 1 Link to comment
Xiaobai Posted October 20, 2014 Share Posted October 20, 2014 Either wait for a new release that supports it or run it using the shell 'osascript' command. Hi, I use JavaScript for Automation and run it using the shell 'osascript' command, but I don't know how to get the arguments in the script. Link to comment
Xiaobai Posted October 20, 2014 Share Posted October 20, 2014 Hi, I use JavaScript for Automation and run it using the shell 'osascript' command, but I don't know how to get the arguments in the script. OK, I have solved the problem, it looks like this: function run(arg){ console.log(arg); } I never wrote applescript and I know nothing about it. I read the document from this url, and I found that the run function. It solved my problem. My English is very bad, I hope you can get it! Link to comment
Caleb Grove Posted October 20, 2014 Author Share Posted October 20, 2014 Xiabai, Close, but not quite close enough. The problem with the <code>run()</code> function is that it requires that the script to be saved as an application rather than a script. That actually makes is rather difficult to run with arguments, unless you like a new terminal window popping up every time you run the workflow. But yeah, that function is basically what I'm looking for, though in a way that can be used in a regular .scpt file. Link to comment
deanishe Posted October 22, 2014 Share Posted October 22, 2014 Theoretically, if you can't wait for the Alfred update, you could create a "runner script" in another language that would accept {query} from Alfred, write it into your JavaScript, then run it with osascript. Link to comment
rice.shawn Posted October 25, 2014 Share Posted October 25, 2014 Theoretically, couldn't you have the applescript read the javascript from a file and then just use the js `eval()` function? Link to comment
deanishe Posted October 28, 2014 Share Posted October 28, 2014 I think if you want to use the JS eval() function, you kinda have to do it from JavaScript… Link to comment
rice.shawn Posted October 28, 2014 Share Posted October 28, 2014 I think if you want to use the JS eval() function, you kinda have to do it from JavaScript. What I mean would be to read the script into a variable and then do set the_js to (whatever the code is to read a file into a variable in applescript) "eval(" + the_js ");" from inside an AppleScript. Granted, I haven't played around with js inside AppleScript yet, so this might be a bust. Link to comment
deanishe Posted October 28, 2014 Share Posted October 28, 2014 That should work. That's what I was getting at in my previous post. Link to comment
rice.shawn Posted October 28, 2014 Share Posted October 28, 2014 That should work. That's what I was getting at in my previous post. Okay, I though that you were mentioning that my previous reply wouldn't work (the one right above yours that says almost the exact same thing). Hence, my clarification. Link to comment
deanishe Posted October 28, 2014 Share Posted October 28, 2014 I was referring to the post before the post that you're referring to. The post above my post that says almost the same thing is not the post I was referring to, but rather the post before the post above my post that says almost the same thing as the post I made that isn't the post I'm referring to. It would be silly to refer to a post that said the same as the post that preceded the post I would, in this case, be referring to. Which is why I'm referring to the post I made before that post. The one that didn't say the same as the post that you think says the same as the post I'm not referring to. Which is not the post I meant. dfay and smarg19 2 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