mabrown Posted April 16, 2013 Share Posted April 16, 2013 The below script works great from terminal using osascript but I can't figure out how to get Alfred to process it. My workflow is a script using osascript and outputting to notification center. on run argv set cpu_ready_ms to item 1 of argv set num_cpu to item 2 of argv set cpu_ready_percent to cpu_ready_ms / (20 * 1000) * 100 / num_cpu end run When run from terminal I get the output I would expect, from Alfred I don't' get any output. I'm new to workflows so I'm sure I'm missing something simple. Thanks, Mike Link to comment
jdfwarrior Posted April 17, 2013 Share Posted April 17, 2013 The below script works great from terminal using osascript but I can't figure out how to get Alfred to process it. My workflow is a script using osascript and outputting to notification center. on run argv set cpu_ready_ms to item 1 of argv set num_cpu to item 2 of argv set cpu_ready_percent to cpu_ready_ms / (20 * 1000) * 100 / num_cpu end run When run from terminal I get the output I would expect, from Alfred I don't' get any output. I'm new to workflows so I'm sure I'm missing something simple. Thanks, Mike Alfred passes all input into the scripts as a single string. If you needed to pass multiple parameters, you could parse the string (using a delimiter) and then pass them individually to the script of your choice. Link to comment
forgetfulfellow Posted October 4, 2013 Share Posted October 4, 2013 (edited) Alfred passes all input into the scripts as a single string. If you needed to pass multiple parameters, you could parse the string (using a delimiter) and then pass them individually to the script of your choice. What language does Alfred parse in? For example, if I passed as output "1.2" to the "post notification" block, how can I just retrieve the "1"? Or the "2"? This would be useful to me if I wanted to make the "post notification" title = "1" and the text = "2" Thanks! Edited October 4, 2013 by forgetfulfellow Link to comment
Tyler Eich Posted October 5, 2013 Share Posted October 5, 2013 (edited) What language does Alfred parse in? For example, if I passed as output "1.2" to the "post notification" block, how can I just retrieve the "1"? Or the "2"? This would be useful to me if I wanted to make the "post notification" title = "1" and the text = "2" Thanks! Alfred doesn't do any parsing on the query; that's where your code comes in Since you're working in AppleScript, this should work: set AppleScript's text item delimiters to {"."} -- Use "." as separator set argv to text items of argv -- This splits the string into a list, using the new separator set cpu_ready_ms to item 1 of argv set num_cpu to item 2 of argv return "CPU Ready Milliseconds: " & cpu_ready_ms & "Num CPU: " & num_cpu -- This returned string becomes {query} Now, as far as sending two separate variables to Alfred's Notification Output: this is not currently possible. Only one variable, {query}, is available. You can use {query} multiple times, though. Cheers Edited October 5, 2013 by Tyler Eich Link to comment
forgetfulfellow Posted October 5, 2013 Share Posted October 5, 2013 Alfred doesn't do any parsing on the query; that's where your code comes in Since you're working in AppleScript, this should work: set AppleScript's text item delimiters to {"."} -- Use "." as separator set argv to text items of argv -- This splits the string into a list, using the new separator set cpu_ready_ms to item 1 of argv set num_cpu to item 2 of argv return "CPU Ready Milliseconds: " & cpu_ready_ms & "Num CPU: " & num_cpu -- This returned string becomes {query} Now, as far as sending two separate variables to Alfred's Notification Output: this is not currently possible. Only one variable, {query}, is available. You can use {query} multiple times, though. Cheers Hey Tyler, Thanks for answering my question. However, my new question then becomes: How can you parse the {query} after you send it as output? Since I want to be using different chunks for different parts of my notification title/text. Thanks! Link to comment
jdfwarrior Posted October 5, 2013 Share Posted October 5, 2013 Hey Tyler, Thanks for answering my question. However, my new question then becomes: How can you parse the {query} after you send it as output? Since I want to be using different chunks for different parts of my notification title/text. Thanks! If you were sending it to another script you could simply use some form of delimiter and then split the pieces based upon that delimiter. You can't do that within the notification output piece though. I would suggest building the full output string that you wish to use in the previous step and then echo/print that. Then the whole string would be available as {query} inside of the notification output item. 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