ThisSpace

One of the first things that happened to me in Spaces that irked me was its auto-switching to another space when I didn’t want it to. Sure, that’s probably what I’d want it to do a lot of the time, but if I’m trying to open a new window for an app that already has windows in other spaces, I have to select that app, create a new window, grab its title bar, and move back to the space I was in when I selected the app.

I was wondering what would happen if you could create a new window without activating the app, so I typed this into Script Editor:

tell application "iTerm"
	set term to (make new terminal)
	tell term
		launch session "default session"
		activate
	end tell
end tell

The result is a brand new iTerm window in my current space, without regard to whether there might already be such a window in another space. Switching spaces from a script is pretty easy too — as long as you aren’t holding down any modifiers when the script runs (say, by having used command-r in Script Editor):

tell application "System Events"
	delay 1 -- so I can let go of command
	keystroke "2" using control down
	delay 1 -- so you can see one switch happen and then the other
	key code 125 using control down
end tell

The one missing piece is moving a window — I don’t think it’s possible to drag an object via GUI scripting, so you can’t grab the title bar of a window, switch spaces, and then release it. At least it might be possible to create a fairly complex setup from a login script…if you had a lot of time on your hands. :)

AppleScript | Tagged , | Permalink | 2 Comments

iTerm/TextMate Here

Yes, again. Inspired by other solutions to the same problems, here are updated versions of these scripts. The primary difference is that they’re based on Apple’s droplet sample, so you can either click on them (for the current directory) or drop stuff on them and it’ll work either way. So, why don’t I just use his scripts, like I do his icons? Beats me — I updated these a week or two ago, and I’ve long since forgotten.1

Continue reading…

  1. While I’m at it, I’ve also forgotten what the other thing was I wanted to do to them before posting this. []

AppleScript | Tagged , , , | Permalink | No Comments

More Little Things

  • The Dock is way too fucking dark. The glass shelf doesn’t thrill me either, but at least it’s a subtle eyesore.
  • Holy crap Spotlight is faster. I used to use Google Desktop based solely on its speed — now it actually has to compete on features.
  • Did I mention that the Dock is too fucking dark?
  • I like the Downloads stack idea — even though I still sometimes reach for the Show Desktop Exposé key to find a download.
  • I’m not crazy about stacks being displayed so literally in the Dock.
  • I don’t really like having to open the stack in Finder to group-delete items either.
  • Do you think it takes the fill color from one of the edge PNGs? That’d make it a lot easier to fix without resorting to ClearDock (when it’s updated for Leopard).
  • The ever-present window drop shadow takes a nap when entering or leaving Time Machine. If they’d kept it, the visual effect of stepping into (or out of) the Way Back might actually work.

Update

No, you cannot change the color of the non-glass-shelf Dock with some simple editing of the obvious images inside Dock.app. For the left side the images are left1.png–left5.png, corresponding to the top edge, the top-right corner, the right edge, the bottom-right corner, and the bottom edge — leaving just 95% of the area of the dock to go. Since I find the dark Dock more unpleasant than the glass-shelf one, I just switched it back to the bottom at a very small size and figured I’ll survive until someone figures out where the fill color lives.

Weblog | Tagged , | Permalink | 1 Comment

The Little Things

Having played around with Leopard for about a day now, here are some of the little details I’ve noticed:

  • Arrows no longer wrap the selected app in the app switcher; if you wanted to switch to the last app in that list, you used to be able to hit left-arrow twice after command-tab. Now, perhaps you’d like something in a nice command-shift-tab.
  • Exactly twice, I’ve gotten the app switcher to show me about five app icons to choose from, when I had more like twenty running, and not in multiple spaces.
  • I’m sure I’ll get those neural pathways rewired to search for the gears icon when I want System Preferences any month now.
  • The subdued Spotlight icon is totally better. Now maybe they can get to work on not showing the fucking thing at all, and just giving me some UI when I ask for it.
  • In fact, the entire menu bar looks better. Granted, I use a relatively light background image, and that might just naturally look better through the translucent menu bar, but I like it.
  • I didn’t see an obvious use glass even on the sides preference string in the Dock’s binary after about 5 seconds of semi-attentive searching driven by a barely measurable interest in the result, so there must not be one.
  • While we’re talking about widely varying Dock appearances based on its position on screen, stacks don’t fan out from the side of the screen (and the View as submenu disappears).
  • For the longest time, I’ve had this dance of scripts that set the DISPLAY environment variable correctly (for the running X11.app) in my iTerm shells, in the off chance that I didn’t end up with :0. The same application (i.e., /Applications/Utilities/X11.app), now cannot be run without starting an xterm. The reason is that it isn’t the X server or even a wrapper for it. Basically, it sets a DISPLAY value somehow and starts an xterm, and lets (I assume) launchd worry about the messy business of actually having X running for it to talk to.
  • Type in a vnc:// URL for an ordinary VNC server into Finder’s Connect to Server dialog and it’ll launch Screen Sharing for you — albeit with a security warning (because an ordinary VNC server doesn’t support any of the ARD security stuff).

Weblog | Tagged , | Permalink | No Comments

Leopard Open Source

I hadn’t seen any mention of this yet when I started my Leopard upgrade, but Apple has added the source code for the open-source parts of Leopard on the Darwin source site. And yes, Virginia, that includes the kernel.

Weblog | Tagged , , | Permalink | No Comments

Later that year…

A while back, John Gruber posted a FastScripts script to fix a loathsome Apple Mail behavior, which was shortly followed by signature-enabled improvements. Fourteen short weeks later, here’s my own version:

tell application "Mail" to activate
tell application "System Events"
	tell process "Mail"
		-- Run the regular "Reply" command
		tell menu bar 1
			click menu bar item "Message"'s menu "Message"'s menu item "Reply"
		end tell
		delay 1.0 -- Give it a chance to finish
 
		-- Remember what signature was selected and switch to "None"
		set blib to value of (pop up button 1 of window 1)
		if blib is not "None" then
			click pop up button 1 of window 1 -- The Signature popup
			click menu item "None" of menu 1 of pop up button 1 of window 1
			delay 0.2
		end if
 
		-- Delete the return Mail inserted; recreate it at the bottom where it belongs
		key code 117 -- Forward delete
		key code 125 using command down -- Command-down (skip to the end)
		key code 36 -- Return
 
		-- Restore the previously selected Signature
		if blib is not "None" then
			click pop up button 1 of window 1 -- Still the Signature popup
			click menu item blib of menu 1 of pop up button 1 of window 1
			delay 0.2
			key code 117 -- Mail inserts a bonus line here too
		end if
	end tell
end tell

One drawback that I maintain from John’s original is the use of a time delay — I have other scripts that use them, and for each of them I occasionally have the script fail because my machine is a little busier that day.1 That being said, this script usually runs correctly.

My improvement is how I deal with arbitrary signatures. If you pick a different signature (or no signature) from the popup menu in the compose window, Mail updates the message correctly — so I just use that behavior to do the messy bits.

  1. Yes I’m still using a PowerBook — what’s that got to do with anything? []

AppleScript | Tagged , , | Permalink | No Comments

Uh…click what?

Having trouble clicking? Try clicking instead:

Clickwhat.png

Rants | Permalink | No Comments

TextMate Here

TextMate Icon

That was actually the first post in a series (of two). This one opens a new TextMate window on the selected item (if there’s a single item selected), or the current folder otherwise. This makes the script a lot shorter (that and there being a simple command-line TextMate launcher that I can use).

The instructions are the same as last time; save it as an application somewhere you can find it, and call it “TextMate Here”. Find it with the Finder, copy and paste TextMate’s icon onto it, and drag it up into your Finder toolbar.

If you have TextMate installed someplace strange (or have an old enough one that it doesn’t have the mate command in it) it will break; if this happens, you get to keep both pieces.

Here’s the script:

on currentFolder()
    tell application "Finder"
        try
            return POSIX path of (front window's folder as text)
        on error
            return null
        end try
    end tell
end currentFolder
 
on selectedItem()
    tell application "Finder"
        try
            get the selection
            return POSIX path of (the result's first item as text)
        end try
    end tell
    return currentFolder()
end selectedItem
 
do shell script "/Applications/TextMate.app/Contents/Resources/mate '" & selectedItem() & "'"

Feedback, improvements, etc. still welcome.

AppleScript | Permalink | No Comments

iTerm Here

iTerm Logo

This is, for lack of a better description, my version of the Open a Command Window Here Windows XP PowerToy. I’ve played around with doing this from the context menu, but I eventually decided I’m not fond of that approach. Since I have the toolbar visible in Finder, however, it’s pretty easy to put a script up there and pretend it’s a real toolbar button.

To use it, save it as an application somewhere you can find it, and call it “Term Here”. Find it with the Finder, copy and paste iTerm’s icon onto it, and drag it up into your Finder toolbar (like how you would drag it into the dock).

My version of this will use the path of the selected item in the front finder window if it is a folder (and is the only thing selected). Otherwise, it will use the path of the Finder window itself. If you want to skip the selection business altogether, just replace the call to selectedFolder() before the last (iTerm) stanza to currentFolder(). It then launches iTerm if needed, create’s a new (empty) window if needed, opens a new tab in that window pushd’s to the directory, and lists its contents for you.

Here’s the script:

on currentFolder()
    tell application "Finder"
        try
            return POSIX path of (front window's folder as text)
        on error
            return null
        end try
    end tell
end currentFolder
 
on selectedFolder()
    try
        tell application "Finder"
            get the selection
            set theItem to result's first item as alias
        end tell
        set theInfo to info for theItem
        if theInfo's folder then
            return POSIX path of theItem
        end if
    end try
    return currentFolder()
end selectedFolder
 
set targetPath to selectedFolder()
tell application "iTerm"
    activate
    try
        set term to the front terminal
    on error
        set term to (make new terminal)
    end try
    tell term
        launch session "default session"
        tell current session
            write text "pushd '" & targetPath & "'"
            write text "ls"
        end tell
    end tell
end tell

Feedback, improvements, etc. welcome. Unless you think it should automatically detect whether iTerm or Terminal is your default terminal program, in which case your feedback is only welcome if you can explain a way to detect this from AppleScript that doesn’t double the length of the script. :) I just don’t care enough about this issue to figure out how to do it.

AppleScript | Permalink | No Comments

Updates

Okay, I rebuilt the site again. Since I didn’t just copy the theme over, there will likely be some formatting quirks. On the plus side, since Wordpress is one-click installed now, hopefully we can stop counting the lag between Erwin updating his blog and me updating mine in months.

Site Info | Permalink | No Comments