Jump to content

Help: run command (without opening Terminal)


dt13

Recommended Posts

First time around here, thanks in advance for your help.
So my question might seem absurdly simple, but my knowledge about advanced Alfred & Terminal is minimal.

 

What I need to learn is how to run a very simple command in Terminal, exactly this: brightness 0.75

 

I've been able to do so in two different ways:

1) directly from Alfred search, using the >

2) creating a workflow that triggers a Terminal Command using a keyword

 

Problem is both of those launch Terminal, and this is what I want to avoid. I'd like for Terminal to run it in the background.

I've read there's a way to do it using the action Run Script instead of the Terminal Command.

 

And here's where I get totally lost. I have no idea how to set up that Run Script to make it work.

Searching through the Forum hasn't helped much, because most questions are by people who know far more than I do, and I get lost in the complexity.

 

I hope you can help me.

Thanks!

Link to comment
1 hour ago, dt13 said:

I have no idea how to set up that Run Script to make it work.

 

Basically, you just need to set its Language to /bin/bash or /bin/zsh and then type your shell commands in the Script box.

 

It’s not quite that simple, as Alfred uses a different PATH to your normal shell, so if a program is in, say, /usr/local/bin, you have to call it via its full path, not just its name (i.e. /usr/local/bin/programname instead of just programname).

Link to comment

@dt13 I have two answers for you. 

 

- The short one: there is a for a workflow for you here.

- The longer one : to complement what @deanishe said, I successfully created an AppleScript script that adjust the brightness to the value you want, as long it is between 0 and 1. 

 

Run_Script_Screenshots.png.2a32d57647439f5d63ee6a7f939b4d3a.png

 

Or, if you absolutely want to use a shell script, please take a look here first.  

 

Run_Script_Screenshots.png.3d8849f745859ee0bf5a03233f42c6bb.png

 

I tried and tested this script. It is working! 

 

I wanted to add a "Large Type" action. One thing, I do not understand is, when I replace the value "0.75" by {query} and "with input as argv" by "with input as {query}", I can't get any notification "Large Type" or "Post Notification" display the value "{query}".

 

If I trigger the workflow with a keyword and an argument, pass this argument/{query} to the script below, shouldn't I be able to output this argument/{query} and be able to display it in a notification ("Large Type" or "Post Notification")? 

 

Quote

/usr/local/bin/brightness {query}

 

Link to comment
3 hours ago, politicus said:

Run_Script_Screenshots.png.2a32d57647439f5d63ee6a7f939b4d3a.png

 

Don't use "with input as {query}" without a good reason. "with input as argv" is simpler and more powerful.

 

There's also no point in using AppleScript here simply to run a shell script. Just set Language = /bin/bash and run the shell script directly.

 

3 hours ago, politicus said:

I wanted to add a "Large Type" action. One thing, I do not understand is, when I replace the value "0.75" by {query} and "with input as argv" by "with input as {query}", I can't get any notification "Large Type" or "Post Notification" display the value "{query}".

 

{query} isn’t like a workflow variable. It means “the output of the previous action”. If an action doesn’t output anything, {query} is empty downstream of that element. If you connect something to a Run Script, its {query} is whatever the script printed.

 

Link to comment

Hey guys!

 

Thanks for your answers! I'm going to go through your suggestions in detail to see if I can start learning a little about all of this.

 

I should have clarified in my first message, but I was in the middle of a night shift and didn't have a lot of time:

  • The reason for using this way instead of using the keys on the keyboard, is because I needed to set the brightness to 0.7953. That adjusts the display brightness to 120lm/m2 which is what I calibrated it to. For certain work, I need it to be at that setting, which is impossible to match using the keys or any of the other tools that I've seen around.

@deanishe I realize I have to first understand the difference between a shell command and a normal command, if there even is one.

@politicus (as your 2nd link suggests) I actually had homebrew installed with the brightness package. That's how I was making it work from Terminal.

 

As I figured it seems like it was embarrassingly simple to solve, but like I said my knowledge is basically zero.

If you have any suggestions as where to start learning/reading (is this coding?), I'd be glad to take any advice.

Edited by dt13
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...