Hattrick Posted December 28, 2019 Share Posted December 28, 2019 Most of the time I use the `> code` keyword, I'm using it to run a one-shot terminal command that doesn't need the terminal window open afterwards. It's a little annoying to have to close the window manually each time. Link to comment Share on other sites More sharing options...
vitor Posted December 28, 2019 Share Posted December 28, 2019 (edited) You can do it by changing Application to Custom in Alfred Preferences → Features → Terminal and setting the code to something like on alfred_script(q) tell application "Terminal" activate do script q quit end tell end alfred_script That’s a start but isn’t it, as that will try to close it too soon. For running one-offs, I recommend RunCommand instead (disclaimer: I’m the author). It will run the commands without opening a Terminal. Edited May 25, 2020 by vitor Hattrick 1 Link to comment Share on other sites More sharing options...
deanishe Posted December 28, 2019 Share Posted December 28, 2019 It might be better to automatically append ; exit to the command if you just want to close the tab/window instead of quitting Terminal.app. Ilia 1 Link to comment Share on other sites More sharing options...
vitor Posted December 29, 2019 Share Posted December 29, 2019 14 hours ago, deanishe said: It might be better to automatically append ; exit to the command if you just want to close the tab/window instead of quitting Terminal.app. We should also be able to tell AppleScript to close the tab (I think Terminal’s AppleScript Dictionary supports that). exit requires changing the terminal profile configuration, since by default it doesn’t close the tab on Apple’s Terminal app. Link to comment Share on other sites More sharing options...
deanishe Posted December 29, 2019 Share Posted December 29, 2019 (edited) 24 minutes ago, vitor said: exit requires changing the terminal profile configuration, since by default it doesn’t close the tab on Apple’s Terminal app. Oh yeah. I forgot about that particular stupidity of Terminal.app (I use iTerm). I'm not sure how simple it is to figure out when the command has finished running via AppleScript, though. Edited December 29, 2019 by deanishe Link to comment Share on other sites More sharing options...
vitor Posted December 29, 2019 Share Posted December 29, 2019 11 minutes ago, deanishe said: I'm not sure how simple it is to figure out when the command has finished running via AppleScript, though. Me neither. Maybe we could combine both solutions and append ; osascript -e 'tell application "Terminal" to quit' to the command. Link to comment Share on other sites More sharing options...
deanishe Posted December 29, 2019 Share Posted December 29, 2019 Mmm. I think it's a bad idea to quit the application. There might be other stuff running in other tabs/windows. Is configuring Terminal.app to close the tab when the last program exits not the correct thing to do in any case? It's default behaviour is so annoying and weird. Link to comment Share on other sites More sharing options...
vitor Posted December 29, 2019 Share Posted December 29, 2019 34 minutes ago, deanishe said: I think it's a bad idea to quit the application. There might be other stuff running in other tabs/windows. Agreed. I thought @Hattrick wanted the app closed, but I stand corrected; the request was to close the window. 38 minutes ago, deanishe said: Is configuring Terminal.app to close the tab when the last program exits not the correct thing to do in any case? It's default behaviour is so annoying and weird. I’d say so. I was also never able to understand why they chose for it to behave like that. Link to comment Share on other sites More sharing options...
tosbsas Posted May 25, 2020 Share Posted May 25, 2020 (edited) how do you configure terminal to close the tab? I mean like daenishe is saying Edited May 25, 2020 by tosbsas Link to comment Share on other sites More sharing options...
vitor Posted May 25, 2020 Share Posted May 25, 2020 1 minute ago, tosbsas said: how do you configure terminal to close the tab? Preferences → Profiles → (pick whichever is yours) → Shell → When the shell exits: (change this). Link to comment Share on other sites More sharing options...
tosbsas Posted May 25, 2020 Share Posted May 25, 2020 thanks Link to comment Share on other sites More sharing options...
Ilia Posted November 16, 2020 Share Posted November 16, 2020 Besides, would that be possible not to raise Terminal window at all and run terminal command in the background? Link to comment Share on other sites More sharing options...
deanishe Posted November 16, 2020 Share Posted November 16, 2020 2 hours ago, Ilia said: Besides, would that be possible not to raise Terminal window at all and run terminal command in the background? Probably, but that would be mostly pointless: if you don't need to interact with the command or see its output, why run it in a terminal? Use a Run Script instead. Link to comment Share on other sites More sharing options...
Ilia Posted November 16, 2020 Share Posted November 16, 2020 (edited) 15 hours ago, deanishe said: why run it in a terminal? Use a Run Script instead. Well, my script produces no result if run using Run Script instead. Could that be because the commands on the script are run as: /usr/bin/nohup /usr/local/bin/sshfs ... 2>/dev/null & ❓ Edited November 17, 2020 by Ilia Link to comment Share on other sites More sharing options...
deanishe Posted November 17, 2020 Share Posted November 17, 2020 17 hours ago, Ilia said: Could that be because the commands on the script are run as It's more likely that whatever it is you're doing requires something from your shell environment. Why don't you try running the command normally, instead of discarding its output, so you can see what's going on? Link to comment Share on other sites More sharing options...
Ilia Posted November 17, 2020 Share Posted November 17, 2020 34 minutes ago, deanishe said: Why don't you try running the command normally, instead of discarding its output, so you can see what's going on? It seems that you are right. When running in terminal, .bashrc is run, which sets PATH with GNU utils, rather than BSD, but in Run Script mode, it's not set and my script is using default BSD sed which fails. I know I can run .bashrc from inside the script to address this issue, however it would be preferable to workaround this issue somehow from inside Alfred? Is this possible? Link to comment Share on other sites More sharing options...
deanishe Posted November 17, 2020 Share Posted November 17, 2020 The best way is generally to use the full path to a command, e.g. /usr/local/bin/sed. If that doesn’t work, put export PATH=/usr/local/bin:$PATH (or whatever you need) at the top of your script to set up the environment. Link to comment Share on other sites More sharing options...
Ilia Posted November 17, 2020 Share Posted November 17, 2020 Well, I could surely do it but the problem is that the script is universally written to be used on both, Linux and MacOS. Would that be possible to add a tick to Run Scripts mode, to include .bashrc? Link to comment Share on other sites More sharing options...
vitor Posted November 17, 2020 Share Posted November 17, 2020 23 minutes ago, Ilia said: Would that be possible to add a tick to Run Scripts mode, to include .bashrc? You’d need a checkbox for every startup file of every shell, and there are a bunch of those. 1 hour ago, Ilia said: I know I can run .bashrc from inside the script to address this issue, however it would be preferable to workaround this issue somehow from inside Alfred? Is this possible? Source the .bashrc inside the Run Script, then. Link to comment Share on other sites More sharing options...
Ilia Posted November 17, 2020 Share Posted November 17, 2020 Thanks for your tips. Indeed sourcing .bashrc makes it work as expected. Example (for future readers): source /Users/user/.bashrc /Users/user/.local/bin/my-script-1.sh Alfred is a masterpiece! ❤️ Link to comment Share on other sites More sharing options...
vitor Posted November 17, 2020 Share Posted November 17, 2020 Just now, Ilia said: /Users/user Use ${HOME}. Link to comment Share on other sites More sharing options...
Ilia Posted November 17, 2020 Share Posted November 17, 2020 Just now, vitor said: Use ${HOME}. Great, will do! Are there other env vars available? Link to comment Share on other sites More sharing options...
vitor Posted November 17, 2020 Share Posted November 17, 2020 2 minutes ago, Ilia said: Are there other env vars available? Run env by itself in a Run Script (connected to a Copy to Clipboard Output or a Large Type Output or something) and see. Ilia 1 Link to comment Share on other sites More sharing options...
Stooovie Posted March 16, 2021 Share Posted March 16, 2021 Hi, I can't get the terminal tabs to close, neither Terminal.app nor iTerm2. I have set the Shell in both to close after finishing. I have also tried to add the ; exit command to my script, but the tabs still keep open after finishing. Any other tips? I'm on Big Sur. I do want to see the terminal while running (transcoding video), so Run Script isn't an option for me. I just want it to close after completion. Thanks! Link to comment Share on other sites More sharing options...
deanishe Posted March 17, 2021 Share Posted March 17, 2021 7 hours ago, Stooovie said: I have also tried to add the ; exit command to my script That does the trick. Are you sure you've formatted your command correctly? Link to comment Share on other sites More sharing options...
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