Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Not sure if this belongs here or on SuperUser, but it's Mac specific, so I'll go with here.

I wrote a Ruby script that edits TextMate's global properties file and changes the theme based on the time of day (light theme during the day, dark theme at night), and then launches TextMate.

I then made an Automator app that runs that script. I called it TextMate, pasted in the flower icon, and put it in my dock instead of the actual TextMate app.

The script works, but the big obvious thing I overlooked is that the real TextMate is no longer in my dock, so whenever I click my Automator version, it runs, exits, and then TextMate appends itself to the running applications section of my dock, so I have two flower icons down there when the app is running. Another problem is that if I opened the app in any other way (like opening a file from Finder), the script won't run.

So, is there any way to attach my script to the actual app, or tell the system to do something any time TextMate opens, or tell TextMate to do something any time it opens?

share|improve this question
    
It might be simpler / more reliable to just have the shellscript run twice a day (around dawn / dusk) at a specific time, using Apple's Launch Services. (The app "Launch Control" is handy for adding/editing LS items.) Just be sure the script checks to see if TextMate is already running, so it doesn't try to write to an in-use .plist file. –  gosmond Feb 25 '13 at 16:45
    
Excellent call, @gosmond. I think I will take this route. –  Andrew Feb 25 '13 at 17:38

2 Answers 2

The third-party UI-scripting application Keyboard Maestro (KBM) can perform this function. (Along with many others.)

I've been using KBM for 5 or 6 years, it's very stable and reliable.

See screenshot of sample KBM script:

enter image description here

share|improve this answer
    
This looks like it would work and would be easy, but 1) it costs money, and 2) by default it overrides a lot of native features like command-tab, and that irks me. –  Andrew Feb 25 '13 at 17:39
    
Re: command-tab in KBM, perhaps it does that by default, but the macros are completely configurable & you can disable or remap any of them. My CMD-TAB works normally, i.e. brings up the standard OS X app switcher. –  gosmond Feb 25 '13 at 17:43
    
I realize. I would upvote your answer if I had the reputation to do so. I'm just being picky. –  Andrew Feb 25 '13 at 18:04
    
It's all good. I realize that a no-cost solution is always preferable to a for-pay. Also, there may be a way to do it programatically with existing or open-source command-line tools. Occam's Razor always applies. –  gosmond Feb 25 '13 at 19:23

If this is really important, you could add:

cmd = `open /Applications/TextMate.app`

(Assuming that's where TextMate is located)

at the end of your script.

That would tell the script to open TextMate after everything else has been run.

Then you just run the script to open TextMate.

share|improve this answer
    
This looks like a good, clean, free solution. If you were getting really fancy, you could have the shell-script just update the .plist file, when the script is called automatically from Launchd -- but when you make an Automator droplet to run the script, in that case pass an argument to have the script actually launch TextMade before it exits. (With sdmeyer's suggested command.) –  gosmond Feb 25 '13 at 23:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.