Wednesday, February 26, 2014

Create a launchpad .app for apps that you run from terminal in OS X

I recently installed Inkscape on OS X, and can run the app by typing
inkscape
in a Terminal window. After this, the GUI window for Inkscape opens.

However, it would be nice to add a shortcut to this app to the OS X launchpad. In order to do this, you can follow the steps detailed in this link. For completeness, I will copy the steps mentioned in the link here.

  • Open the AppleScript Editor application. 
  • Type the following text in the editor window:
    tell application "Terminal"
      do script "`which yourAppName`; exit"
    end tell
    
    (Make sure you replace yourAppName with the name of the App!)
  • Then click Save from the File menu. 
  • Pick Application as the File Type
  • Save it in the Application folder with YourArbitraryName.
You are done!

You can also set a custom image for the app's icon:
  • Copy a custom image to the clip-board.
  • Open the Application folder in Finder.
  • Right-click on the newly created app (YourArbitraryName.app).
  • Select Get Info from the menu. 
  • At the top-left of the info window, click on the current icon to select it.
  • Press Command-v to paste the image from the clip-board over the current icon.
Enjoy the custom icon!

 Neater way

The only problem with the above method, is that if your app has a GUI, nonetheless a Terminal window will also be opened and will stay open. What if you want the Terminal window to open, launch your app, and close? I got some hint on how to do just that from this link.

The solution is, just replace the above AppleScript with the one below.
tell application "Terminal"
  do script "`which yourAppName` & exit"
  if (count of (every window whose visible is true)) ≤ 1 then
    quit
  else
    close window 1 without saving
  end if
end tell

No comments:

Post a Comment