Jump to content

Execute a command via terminal (not showing it) ?


face

Recommended Posts

Hi all,

i know it's possibile to execute a terminal command using > (command_to_execute)

I'd like to create a script where simply inserting a command in Alfred

i.e. Test

automagically execute the command via terminal WITHOUT showing the terminal app

is it possible ?

Link to comment

@vitor thanks

actually i've used this terminal command

pcsctest
1
1
exit

but, even if in the terminal shell i've selected in preferences > profile > shell to

close the window when the shell is finished

the terminal app not close itself

why ?

i've tried adding a: 

Key combo with cmd + q

and it seems to work but seems that the command in terminal isn't executed completely or i'm wrong ?

But obviously using terminal command the terminal app is visible ... 

 

Any help to use instead the Run Script Action ?

I'm looking through help section / examples but frankly i don't understand how to achieve it ...

Edited by face
Link to comment

What’s the 1 meant to achieve? If you’re hoping that’s given as the input to to pcsctest, it isn’t, it’s going to be run as separate commands.

 

That command seems to output information, not do anything. What exactly are you trying to achieve?

Link to comment

I need to wake up a USB port where is inserted a token (last OS X unfortunately puts the USB ports asleep after some time).

If the USB port is asleep i cannot use that token using a remote connection.

I can wake up USB only if i'm physically near the Mac removing / inserting the token.

I hope with pcsctest terminal command i can wake up the USB port.

Hope is clearer now 😀

 

Link to comment
10 hours ago, face said:

Any help to use instead the Run Script Action ?

 

Just put your command in there, instead of in a Terminal Command, and set the Language option to /bin/bash.

 

10 hours ago, face said:

i've tried adding a: 

Key combo with cmd + q

 

That won't work. When you use a Terminal Command, Alfred passes the command to Terminal.app (or iTerm2). It does not wait for the command to complete because it's not a two-way action. So your CMD+Q is being sent immediately, quitting Terminal.app before the command is run.

Link to comment

While this workflow

pcsctest
1
1

works like a charm giving in the terminal the correct execution:

pcsctest

1

1

Last login: Mon Oct 21 23:46:04 on ttys000



The default interactive shell is now zsh.

To update your account to use zsh, please run `chsh -s /bin/zsh`.

For more details, please visit https://support.apple.com/kb/HT208050.

Fabrizio:~ Fabrizio$ pcsctest



MUSCLE PC/SC Lite Test Program



Testing SCardEstablishContext    : Command successful.

Testing SCardGetStatusChange 

Please insert a working reader   : Command successful.

Testing SCardListReaders         : Command successful.

Reader 01: Bit4id miniLector-s

Enter the reader number          : 1

1

Waiting for card insertion         

                                 : Command successful.

Testing SCardConnect             : Command successful.

Testing SCardStatus              : Command successful.

Current Reader Name              : Bit4id miniLector-s

Current Reader State             : 0x54

Current Reader Protocol          : 0x1

Current Reader ATR Size          : 25 (0x19)

Current Reader ATR Value         : 3B FF 18 00 00 81 31 FE 45 00 6B 11 05 07 00 01 21 01 43 4E 53 10 31 80 4A 

Testing SCardDisconnect          : Command successful.

Testing SCardReleaseContext      : Command successful.

Testing SCardEstablishContext    : Command successful.

Testing SCardGetStatusChange 

Please insert a working reader   : Command successful.

Testing SCardListReaders         : Command successful.

Reader 01: Bit4id miniLector-s

Enter the reader number          : Waiting for card insertion         

                                 : Command successful.

Testing SCardConnect             : Command successful.

Testing SCardStatus              : Command successful.

Current Reader Name              : Bit4id miniLector-s

Current Reader State             : 0x54

Current Reader Protocol          : 0x1

Current Reader ATR Size          : 25 (0x19)

Current Reader ATR Value         : 3B FF 18 00 00 81 31 FE 45 00 6B 11 05 07 00 01 21 01 43 4E 53 10 31 80 4A 

Testing SCardDisconnect          : Command successful.

Testing SCardReleaseContext      : Command successful.



PC/SC Test Completed Successfully !

Fabrizio:~ Fabrizio$ 

and in dAlfred's debuggers appears:

[06:21:57.880] PCT[Keyword] Processing complete

[06:21:57.881] PCT[Keyword] Passing output '' to Terminal Command

 

 

If i insert that workflow in a Run Script (inserting each line in 3 different Actions Run Script (as suggested, if i well understand) i receive this output in the debugger:

[06:24:13.888] PCT - INVISIBILE[Keyword] Processing complete

[06:24:13.889] PCT - INVISIBILE[Keyword] Passing output '' to Run Script

[06:24:13.978] PCT - INVISIBILE[Run Script] Processing complete

[06:24:13.981] PCT - INVISIBILE[Run Script] Passing output '

MUSCLE PC/SC Lite Test Program



Testing SCardEstablishContext    : Command successful.

Testing SCardGetStatusChange 

Please insert a working reader   : Command successful.

Testing SCardListReaders         : Command successful.

Reader 01: Bit4id miniLector-s

Enter the reader number          : ' to Run Script

[06:24:14.047] STDERR: PCT - INVISIBILE[Run Script] /Users/Fabrizio/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/6FA39E5A-6306-4AFD-9BB8-C41A84D677BB: line 2: 1: command not found

[06:24:14.051] PCT - INVISIBILE[Run Script] Processing complete

[06:24:14.053] PCT - INVISIBILE[Run Script] Passing output 'MUSCLE PC/SC Lite Test Program Testing SCardEstablishContext : Command successful. Testing SCardGetStatusChange Please insert a working reader : Command successful. Testing SCardListReaders : Command successful. Reader 01: Bit4id miniLector-s Enter the reader number :' to Run Script

[06:24:14.115] STDERR: PCT - INVISIBILE[Run Script] /Users/Fabrizio/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/EFC99D78-F529-443D-81B3-526EAB14E311: line 2: 1: command not found

Why it doesn't work ?

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...