How to create dock icon for running terminal command in Mac OS - macos

Now I open jmeter using terminal using command: open /usr/local/bin/jmeter
I need it frequently, so I want to create dock icon to run this command.
How can I do it?
I tried to make a right click and choose 'keep in dock' option. However, it disappears when I close the application.

The closest I could get was creating a desktop icon through the following method:
Create a plain text document in TextEdit
Paste the following code in the document
#!/bin/bash
open /usr/local/bin/jmeter
Save the file as fileName.command
Open Terminal and navigate to the directory which you saved the file
Type in chmod +x fileName.command and hit enter
You should now have a shortcut to execute this command! I know this isn't the exact solution you were looking for, but I hope this still solves your problem.

Following E. Zimbelman's answer, you create a .command executable file and then
you can add an icon (drag and drop an icon file on the icon of the properties window of the file (Cmd+I))
change the .command extension to .app
so you can add it the the dock (drag and drop), it's ok if the icon has changed temporarily
and then you change it back to .command
With this you can have any script you like in the .command file and have it on mac's dock.

I suggest you have a look at the answer to this question in the apple stackexchange. It pretty much does exactly what you want (although I have no idea what jmeter does).
The answer is, essentially, use automator to run your script, save the automator job as an app (not a workflow), and drag the resulting object to the dock, once you have it working the way you want.
https://apple.stackexchange.com/questions/73897/how-can-i-launch-a-virtualbox-vm-from-the-dock
or the wayback machine copy:
https://web.archive.org/web/20160921184459/https://apple.stackexchange.com/questions/73897/how-can-i-launch-a-virtualbox-vm-from-the-dock

I needed a simple terminal command to unmount an internal disk which keeps spinning up whilst appearing in Finder to be unmounted. I am running the Mac from an external SSD.
All that was required was to open Script Editor and enter the text:
do shell script "diskutil eject /dev/nameofthedisk"
and then save that as an Application. Drag that to the dock and now I have one click unmounting of the disk when it spins up.

Related

Batch copy file name action in Apple Script for Automator Mac OS X

Can one automate the process of copying a file name and pasting it in the Spotlight Comment box of that file? How does that Apple Script for OS X looks like?
I would need to do that a thousand times otherwise:
Hitting enter to select the file
Short cut typing Hotkey Cmd C
Short cut typing Hotkey Cmd I to open that info window
Hitting tab button twice to enter the Spotlight Comment box
Short cut typing Hotkey Cmd v
Short cut typing Hotkey Cmd w to close that info window
The aformentioned folder contains a thousand files and even more.
Automator has that function built right in, via the Set Spotlight Comments for Finder Items Action:
You should be able to point the first action at your target folder, have it find all the files, and it will add the Comment to all of them.
Good luck,

Run an apple script saved as run only so icon doesnt show in dock

I created an apple script and placed on my desktop. I first saved it as .app and when double clicked it ran code successfully and closed. However in the time it would run it would show an icon in my dock.
So to avoid that i thought lets save it as a run only script. So I did that but now when I double click it, it doesn't run the script, it just says 'it was saved as read only and cannot open'.
You can edit the Contents/Info.plist (easy with Xcode) located in the app bundle and add a Application is agent (UIElement) - Key with value YES to it. Now it shouldn't show in the Dock when running.
The raw text to include is:
<key>LSUIElement</key>
<true/>
Change your run only script's extension from ".scpt" to ".app" and you should be able to run the thing.
More information can be found in this closely related question.

Open a shell script in Terminal (Mac) no matter what the default application for bash scripts is set to

I wrote a shell script that I'm distributing to my friends. On my computer, it works great, because I set the default application for shell scripts to be Terminal. However, when my friends open it, the script opens in TextEdit. Is there a way to add an argument to the shell script before it launches so it opens in Terminal instead of a text editor?
Thanks
PS, I did chmod a+x to the file. I also made sure to add #!/bin/sh to the script. I've also been testing with using the extensions .command, .cmd, and .tool. That would solve my problem except then Gatekeeper won't let the script run because I'm not a registered Apple Developer.
If there were a way to make double-clicking a file run it, then that would be the sort of security hole that Gatekeeper is designed to prevent. So, Apple has plugged any such holes they can think of.
Send the file to your friends as a .command file and tell them to right-click or Control-click on it and choose Open. This will change the Gatekeeper dialog to a warning, but with an "Open" button to let them go ahead and open it anyway. The system will prompt them for an administrator password to record the grant of permission in a permanent way. They'll be able to open with a simple double-click from then on.

"Open folder in Terminal" for Spotlight or Alfred

Is there any way in Spotlight to have a folder open in a Terminal window, either by providing an "Open in Terminal" option in search results, or (ideally) by holding down a key when selecting a result? Basically the same way holding down command will "Open containing folder" maybe make it so holding option (or whatever key) could "Open in Terminal".
Alternately, is there a way to setup the Alfred app so that it will always open folder search results in the Terminal? that might be even better, then I could use ctrl-space exclusively for opening folders in the Terminal and command-space (Spotlight) for everything else.
The closest thing I can find to anything like these is the "cdto" application, which adds an "Open in Terminal" button to the Finder. This is nice, but being able to do this directly from Spotlight or with a keypress would be much more convenient.
This question is old and you undoubtedly found the answer by now; for the sake of completeness: the latest version of Alfred allows one to search/navigate the filesystem from within Alfred, and take action on the folder or file found. One folder action is "Open Terminal Here", which seems to be what you are asking for.
I've found this to be the fastest method without any external tinkering.
Requirement: need to have iTerm or Terminal in the Dock:
Type the folder name into Alfred / Spotlight
Click and drag the folder that was found into the iTerm / Terminal icon in the Dock
Try this tool:
https://github.com/nmadhok/OpenInTerminal
This is a really handy tool for programmers on Mac as it lets you open the folder directly in Terminal. You can select multiple folders to open them in multiple terminal windows. You can also select files to open the parent directory in Terminal. This application works with Finder as well as without Finder which is a plus!
use this Alfred extension
https://github.com/LeEnno/alfred-terminalfinder
then just lob off the input and set it to a hotkey.. I have one to open the current finder in terminal and vice-versa
#Verboze - I'm still looking for an answer :)
Perhaps it should be migrated to stack exchange or the other one used non-programming topics, such as system administrivia. Though a case could be made that the command line is essential to programming.....
Windows has "Command Prompt Here". Linux has Nautilus' "Open In Terminal". The world's most advanced operating system has nothing (the best I can tell).
For completeness, I did look at the customizable toolbar ('drag your favorites here'; but my favorite is missing). I also found an old Action Script or Automator Script that did not work (the article was old, and it could not be followed).
I did find a program called "CD To...", but its broken. Upon opening the first terminal, the program opens two terminals. I'm not sure what other programming mistakes were made by the developer, and I really don't want to experiment.
Check this: https://github.com/miromannino/alfred-new-terminal-window
It opens a new Terminal/iTerm window in the current space.
Holding the alt key, the new window is also opened opened in the current frontmost Finder folder.
For me that is almost sufficient for my daily work!
Hope it helps!

New OSX User: Opening up a new terminal window in current space(?)

I'm just meddling with OSX after a few years on Linux. There's a lot that I'm liking, but one thing that's slowing me down is that if I run the 'terminal' command via shortcut/spotlight/quicksilver, it whisks me off to any existing terminal in whatever space already has a terminal instance open.
I regularly like to pop up a terminal, run a quick command and then close it again, all the while staying in whatever desktop space I happen to be on.
...So, how do I do that on Mac?
Cheers...
Go to System Preferences -> Exposé & Spaces -> Spaces and check When switching to an application, switch to...
Download this tool called Visor
It lets you quickly get a tabbed drop down terminal using a hotkey like Ctrl-`.
Insanely convenient for working in the shell.
Try this tool: https://github.com/nmadhok/OpenInTerminal
This is a really handy tool for programmers on Mac as it lets you open the folder directly in Terminal. You can select multiple folders to open them in multiple terminal windows. You can also select files to open the parent directory in Terminal. This application works with Finder as well as without Finder which is a plus!

Resources