OS X Launcher Applet For X11 Apps
Monday, September 12th, 2011Trying to get my favorite text editor SciTE fully integrated into OS X required me to figure out some AppleScripting. I found a non-functioning SciTE launcher somewhere on the interwebs, but it only contained binaries, no script to tweak (how rude). Basically, I pulled apart the broken SciTE.app and found I could stick an AppleScript in there (called “main” in the directory structure below). This is what SciTE.app currently looks like when you “Show Package Contents”.

Here’s the script I ended up with, it evolved as I overcame various hurdles. It writes to a file on the desktop to log errors, or if you set debugmode to true:
global debugmode
# Arguments passed on command line...
on run argv
set debugmode to false
runFilelist(argv)
end run
# Arguments passed with Finder...
on open filelist
set debugmode to false
if filelist is {} then runScite("")
runFilelist(filelist)
end open
on quoted(f)
return quoted form of POSIX path of f
end quoted
on runScite(argstring)
try
# All the guff at the end is required to prevent the script waiting for execution to terminate
# otherwise this apple script will only work once
do shell script "/opt/local/bin/scite " & argstring & " > /dev/null 2>&1 & "
on error the error_message number the error_number
set the error_text to "Fatal Error: " & the error_number & ". " & the error_message
my write_error_log(the error_text)
end try
end runScite
on runFilelist(filelist)
set filename to missing value
set filenames to ""
try
if (count of filelist) is greater than 0 then
repeat with filename in filelist
set filenames to filenames & " " & quoted(filename)
end repeat
end if
if debugmode is true then
set the error_text to "Debug: filenames = " & filenames
my write_error_log(the error_text)
end if
runScite(filenames)
on error the error_message number the error_number
if debugmode is true then
set the error_text to "Error: " & the error_number & ". " & the error_message
my write_error_log(the error_text)
else
runScite("")
end if
end try
end runFilelist
on write_error_log(this_error)
set the error_log to ((path to desktop) as text) & "SciTE.app_Error.txt"
try
open for access file the error_log with write permission
write (this_error & return) to file the error_log starting at eof
close access file the error_log
on error
try
close access file the error_log
end try
end try
end write_error_log
You can drag this into your apps folder, stick it on your dock and just generally let the good times roll. Getting file associations working required some more awesome copy/paste action however. Basically I just found a text editor that supported lots of code languages and edited the Info.plist such that some of the labels and values looked more appropriate for my SciTE launcher and put it in the SciTE.app package. This allowed me to “Open With” files using SciTE, however I couldn’t set default file associations for file types until I added CFBundleIdentifier to Info.plist. Possibly something was corrupted because even after that it didn’t work, though maybe I just needed to reboot it or something. I tried installing RCDefaultApp, but that was fail, even after I got it working RCDefaultApp refused to set file associations to my launcher. The symptom I was experiencing was selecting Open With SciTE from both the “Get Info” and “Open With…” would work for a single file, but if I tried to make it default, it would flick straight back to xcode or whatever the default file handler was. Here’s what I tried before I noticed it finally working:
- Created a CFBundleIdentifier element in Info.plist
- Ran “/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f /Applications/SciTE.app” both with and without sudo. This gave me some weird message about Throttline IO that I didn’t understand.
- Ran “/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user” both with and without sudo (I think).
- Rebooted
This is when I noticed RCDefaultApp wasn’t helping me at all, it still wouldn’t work, so I removed it. Using “Get Info” to set my launcher as the default did finally work by this stage.
Here’s the launcher, enjoy! SciTE.app
(I’m still on Snow Leopard by the way I have no idea if this works on Lion yet)
If you have trouble figuring out what to enter into those fields, check out my old 
