Jump to content

Additional arguments to Terminal Command


Recommended Posts

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

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

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

Link to comment

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

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 by deanishe
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...