Skip to content

www.rolfje.com

Starting Java app from Applescript

Posted on 2009-06-11 By rolfje No Comments on Starting Java app from Applescript

Suppose you have a Java Swing application which you can start by typing the following on the command line:

java -jar myTerrificSwingApp.jar

If you want to make that application start from the Finder in OSX, there are a lot of options which range from ugly to convoluted. If you need a quick fix, here’s how to do it.

Open ScriptEditor.app on your Mac, and copy paste:

— Get path to this script using “/” in stead of “:” as seperators

set myPath to POSIX path of (path to me as string)

— Save text item delimiters and set it to “/”

set delims to AppleScript‘s text item delimiters

set AppleScript‘s text item delimiters to “/”

— Get the whole string except the last token, and add a “/”

set myFolder to (text 1 thru text item -2 of myPath) & “/” ¬

as Unicode text

— Restore default text item delimiters (being tidy)

set AppleScript‘s text item delimiters to delims

— Start java from this directory, as nohup and background

— so this applescript can disapear from the Dock

do shell script ¬

“cd “ & myFolder & ¬

“; nohup java -jar myTerrificSwingApp.jar &”

Save the script as “Application Bundle” and don’t forget to un-check the startup window option. If you have some extra time, you can open the package contents of the app, and replace the Contents/Resources/applet.icns with your own icon.

There are a lot more ways to do this, for instance you can also put your jar file inside the app bundle, or build a double-clickable jar file, or bundle a complete application. You can find more info on all these options on the Apple developer website.

Apple, Software Tags:osx, programming, Utilities

Post navigation

Previous Post: T(w)inkering
Next Post: Why you want a Polarizer Filter

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

           

Recent Comments

  • rolfje on Methode Buijs uitgelegd
  • LinkedIn is at Peak Enshittifaction – Will Chatham's Blog on Linked-In not really Opt-in?
  • Hans j on 1N4148 diode as RF switch
  • Roaming Rhonda on DLNA on OSX, done right
  • Frans on How to fix a Krups XN2001 Nespresso machine

Tags

Anonimatron Apple backup design DIY DRM eclipse environment Fun gmail google hacking hamradio Hardware helicopter iphone ipod iTunes Java Keynote maven modelling motorcycle music news opinion oracle osx photo photography programming repair review security Software Steve Jobs T-Mobile technology Time Machine Ubuntu usability Utilities vacation windows Workshop

Categories

  • Apple (105)
  • Divorce (1)
  • Electronics (3)
  • Fun (57)
  • Games (7)
  • Hardware (72)
  • Microsoft (18)
  • Racing (14)
  • Software (134)
  • Uncategorized (65)
  • Workshop (20)

Archives

Copyright © 2025 www.rolfje.com.

Powered by PressBook WordPress theme