davedelong Posted December 20, 2014 Share Posted December 20, 2014 I have a workflow with two nearly identical keyword triggers and two nearly identical terminal commands. The terminal commands differ only in one regard: which user I want to perform the command as (root vs the current user), and the triggers differ only in the prompt text. It looks like this: ┌─────┐ ┌─────┐ │ dev │ → │ cmd │ └─────┘ └─────┘ ┌─────┐ ┌─────┐ │ dev │ → │ cmd │ └─────┘ └─────┘ Ideally, I'd like to have a way to pass an extra parameter into the terminal command, so that I can make it more like this: ┌─────┐ │ dev │ └─────┘ ↘︎ ┌─────┐ │ cmd │ ┌─────┐ ↗︎ └─────┘ │ dev │ └─────┘ The Terminal command is rather complex, and if I have to update it, I'd like to only update it in one spot. Is there a way I can pass additional information in to the command based on which trigger is invoking it? Link to comment
wolph Posted December 20, 2014 Share Posted December 20, 2014 You could use the mod argument for that See the docs: http://support.alfredapp.com/workflows:config:inputs-script-filter#toc15 <subtitle mod="shift">Subtext when shift is pressed</subtitle> <subtitle mod="fn">Subtext when fn is pressed</subtitle> <subtitle mod="ctrl">Subtext when ctrl is pressed</subtitle> <subtitle mod="alt">Subtext when alt is pressed</subtitle> <subtitle mod="cmd">Subtext when cmd is pressed</subtitle> Link to comment
davedelong Posted December 20, 2014 Author Share Posted December 20, 2014 Modifiers are the reverse of what I want to do. A modifier would let me have a single keyword action go to multiple outputs. I want multiple keywords going to a single output. Link to comment
wolph Posted December 20, 2014 Share Posted December 20, 2014 In that case a keyword won't do the trick. You'll have to use a scriptfilter. With a scriptfilter you simply modify the "arg" parameter and you're done Link to comment
Andrew Posted December 20, 2014 Share Posted December 20, 2014 This type of scenario will be much easier in the future when I overhaul the workflow architecture, but for now, wolph is right... a simple script filter will likely serve your needs. You could always run into a script action which then opens the terminal with the script you want if you need to process the script before opening Terminal smarg19 1 Link to comment
rice.shawn Posted December 20, 2014 Share Posted December 20, 2014 Until Andrew finishes these fabulous things he's been mentioning, you can actually just simulate the two-to-one with a one-to-one. Without anymore information, what I'd do is:(1) Create a script filter that is sensitive to the variable: `$USER` that would give you separate prompts. (2) For the script action, put a conditional in there, making use of the variable `$USER` to make sure the command is just right. I'm not sure what language you're working with, but, to access that variable you do: AppleScript: system attribute "USER" Bash: $USER Ruby: ENV['USER'] PHP: $_SERVER['USER'] Python: os.environ['USER'] Link to comment
deanishe Posted December 27, 2014 Share Posted December 27, 2014 (edited) How about putting the terminal command in a separate script (e.g. mycommand.sh) and sticking with 2 Run Script actions, one with ./mycommand.sh and one with sudo ./mycommand.sh? This type of scenario will be much easier in the future when I overhaul the workflow architecture, but for now, wolph is right... a simple script filter will likely serve your needs. You could always run into a script action which then opens the terminal with the script you want if you need to process the script before opening Terminal This has me intrigued… Edited December 27, 2014 by deanishe 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