face Posted October 20, 2019 Share Posted October 20, 2019 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 Posted October 20, 2019 Share Posted October 20, 2019 You’re looking for the Run Script Action. Note that Alfred doesn’t inherit your Terminal’s path, so you may need to export it or (works for most cases) give the full path to the tools you’re running (e.g. /usr/local/bin/myscript instead of myscript). Link to comment
face Posted October 21, 2019 Author Share Posted October 21, 2019 (edited) @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 October 21, 2019 by face Link to comment
vitor Posted October 21, 2019 Share Posted October 21, 2019 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
face Posted October 21, 2019 Author Share Posted October 21, 2019 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
deanishe Posted October 21, 2019 Share Posted October 21, 2019 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
face Posted October 21, 2019 Author Share Posted October 21, 2019 @deanishe i've inserted in a Run Script this code: query=$1 pcsctest 1 1 exit echo -n $query That's all ? How to know that the command is executed ? Link to comment
deanishe Posted October 21, 2019 Share Posted October 21, 2019 That's not a valid command. @vitor already told you that above. 1 is not a valid command, and you can't run anything after calling exit. That ends the script. Link to comment
face Posted October 21, 2019 Author Share Posted October 21, 2019 (edited) Delete Edited October 21, 2019 by face Link to comment
deanishe Posted October 21, 2019 Share Posted October 21, 2019 If anything goes wrong, there'll be an error message in Alfred's debugger. Link to comment
face Posted October 22, 2019 Author Share Posted October 22, 2019 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
deanishe Posted October 22, 2019 Share Posted October 22, 2019 3 hours ago, face said: Why it doesn't work ? It doesn't work because it's an interactive command. It needs to be run in a terminal because it requires you to enter input. Link to comment
face Posted October 22, 2019 Author Share Posted October 22, 2019 so no way to use Run Script Action ? Link to comment
deanishe Posted October 22, 2019 Share Posted October 22, 2019 Well, no. If the program doesn't have a non-interactive mode, you can't run it in a non-interactive way. It will either fail or wait forever for input that will never come. You can try to write a script that interacts with pcsctest for you, but that's complicated and error-prone. 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