Applescript and launchctl equals beachball

AppleScript I hate. The concept to have a scripting system to drive Applications is great. The implementation sucks ass. No, really, it’s worth this trip into the dumb language bin. AppleScript is a stupid hack. It’s syntax makes no sense for anybody. Only a couple (and I mean less than hundret) zealots that happen to get scared of any real language still use it. Worst of all: the makers of AppleScript are still with Apple and have given us “Automator”. Just add another layer of crap over another one. AppleScript thinks that people want ‘human readable code’. No they don’t. Specially if it makes no sense at all. End of rant.

It is also plain broken:
launchctl is the utility to start and stop processes for Apples launchd tool. For an application I am writing I would like to start / stop services, and launchctl does just that. I can create a .command file and that makes a shell script clickable. The only caveat is that terminal will launch and the window will not go away once the script is done. Not as neat as it should be. As an aside: stay away from the “Save Settings as Defaults” in Terminal.app. This will also save your current running application for instance as that. If you have a login to another machine, than all future Terminal windows will want to log in to that machine. The remedy is to trash the terminal.plist out of ~/Library/Prefecenses. And the ‘close winow when shell exits’ option does not work. Hence the detour to Applescript. But, that does not work either, since Applescript just beachballs if it launches a launchtl unload ... for instance.

Applescript is a freaking hack. It makes me sad and angry (ok, actually that would be an overstated, computers don't that do that anymore to me) since it's sitting in a place that an amazing application could occupy. Imagine any decent widespread syntax, an API library to all Applications and some GUI glue. That together with some way of version manage / download these 'system scripts' and you would have lots of people developing nice short cuts, meta apps or whatever you want to call it. It would be extending what Unix did 30 years ago for command line applications. Use Photoshop, mail and iDVD in one workflow for instance. Or google, iTunes and a printer in another. You see, it would be awesome. For everybody. But instead Sal and Co. give us what they can come up with. Which is frankly not much. Sigh.

3 Responses to “Applescript and launchctl equals beachball”

  1. Nick Says:

    Hi There,

    I consider myself to be a competant programmer. I have picked and up and used over 15 languages over my time.

    Applescript is easy to read and easy to use. It offers something that you simply can’t get as easily with a PC. Having programmed solely on the PC for over 10 years I can tell you that applescript is simple, fine it’s not java and its not VB but then that’s why it’s called applescript.

    I suggest you learn how to program my friend. Try Prolog. Try Occam. Basicaly try a hard language and then come back and complain about applescript. I mean the word script tells you it’s going to be easy!

    Nick - clearly a better programmer then you

  2. Andreas Wacker Says:

    Great comment.

    Not sure how to reply to it.

    I consider myself to be a mediocre coder. At best. I know so many people that I can learn from. Which is great.

    The problem with Applescript is that it is pseudo easy. You might be able to copy paste some code here and there, and do some hello world variations. But for anything serious I have not found ways doing them in AppleScript. It’s kind of weird that I always ended up generating the AppleScript code in other languages, in order to get something done.

    Which is a real shame. Imagine Apple would have given, let’s say javascript, the API keys to the kingdom! How great would it be to run Applications via that!!

    Andreas - who is not wondering what kind of software Nick wrote in those 15 languages.

  3. jamy Says:

    Hi, I came across this post while googling for yet another simple answer to what takes me forever to understand… coding lol.
    But I thought I would offer my .02 anyway.
    I am a terrible coder if I can be so honest. It takes me 3 times as long to code a window to close in than you guys would take to write a complete app. And it only took me a few minutes to understand how Applescript can talk to the OS using shell scripts, that don’t open the Terminal window, and also how to talk to launchctl.
    Here is my launchctl code that loads (or unloads) a launchAgent… and it works well for me. Yes, I had a couple challenges, namely finding the code in the first place, then making sure my permissions on the plist in the LaunchAgents folder were correct, but it worked well and still does.

    do shell script “launchctl load -w $HOME/Library/LaunchAgents/com.myCode.plist &”

    Just substitute load for unload. No Terminal window, and with the messages I wrote for it, the console keeps me informed with:
    do shell script “logger MyApp - It is Launched! &”

    Point is, if I can do it, I know that you can. :)

    So far, there is absolutely nothing I have seen that I couldn’t do with AS whether directly through the scripting language itself, or with its ability to communicate with the Terminal in the background.

    Call it a hack, ok, I’ll take it. Just don’t call me a hacker, I’m not good enough for that :) … but I get a lot done with well written Applescripts.

    I agree with Nick, who is clearly a better programmer than me!

    Applescript rules on my Macs, and for many folks that my scripts have helped doing simple things that so called “great programmers” left out.

    Hope you’re having better luck with AS now.
    Jamy

Leave a Reply

You must be logged in to post a comment.