Tag Archives: AppleScript

Sublime Text 2 New Window (via AppleScript)

Building upon my older post on opening new window in Text Mate 2, I now threw together small script to do the same in Sublime Text 2.

While Sublime Text 2 is superb text editor, it is not Mac native, thus it’s even less probable that a new Mac-style Dock icon menu will appear in near future, that allows opening new window quickly. Thus a helper application is in order.

SublNewWindow

Based on the original TMNewWindow code, only small modifications were needed. One unexpected behavior was with detecting working state of the application. For whatever reason the original script gave errors when run against Sublime Text 2.

Again, the AppleScript application is linked below and feel free to send me updates and patches if needed.

 


 

Mount partitions like a boss (AppleScript)

How to quickly mount partitions when the need arises? A small AppleScript to help you out.

The need

No good comes without little drawbacks. When I swapped ODD with HDD, I noticed that it was quite a bit noisier than SSD and even compared to similar MBP with HDD in original bay (probably because ODD bay has a slot that lets noise out easily). So, now I tend to eject the secondary disk when I don’t need it, so my Mac can spin it down. All nice and dandy, but reattaching it when needed was a bit tedious.

The Script

set partList to {"Meedia", "BOOTCAMP"}
choose from list partList with prompt "Choose partitions" with multiple selections allowed
if result is not equal to false then
	repeat with part in result
		do shell script "diskutil mount " & part
		display dialog "Volume " & part & " mounted"
	end repeat
end if

This script asks for which of the partitions to mount and then iterates with diskutil through the selection.

Download

You can copy-paste the above script to AppleScript Editor and adjust it to your needs, or you can download this as a ready to use application.

MountPartitions.zip

 

TextMate 2 New Window (via AppleScript)

Often I find myself in a situation where I need to quickly paste some text and edit it a bit. Switching to TextMate also switches spaces to my last TM session, which might not be my current space. With other programs (and TextMate 1 for that matter) this can be overcome by selecting “New file” or “New window” from dock menu.

But the problem is that TextMate 2 alpha currently does not have
“New file” option in the Dock menu. I really miss this, because of my workflow – I use spaces to manage projects and programs I have open concurrently and I don’t want to mix the TextMate windows between spaces. So opening new TM2 window in current space is a must.

But surely the developers are preoccupied with more important features and thus I decided to throw in my 2 cents and cobbled together an AppleScript that one can use to open new window in current space.

TMNewWindow

Place this script in your Applications folder and wait until Spotlight has indexed it. Then push whatever shortcut you have for Spotlight (or Alfred, if you are like me) and enter few first chars. I have found that tmn is enough to trigger this application.

Hitting enter will fire this app and a sec later new TextMate window should be opened in current space. Definitely faster than switching to TM2, hitting ⌘N and then moving the window to correct space.

 

▼ Download TMNewWindow

 

 

BetterTouchTool and Safari

EDIT: Mountain Lion seemed to have issues with this script, so download new version below or read more here: Safari New Window.

Few days ago I switched to BetterTouchTool from MagicPrefs because (1) MP somehow blocked clicks when MagicMouse was disconnected and I always had to quit the MP. And (2) BTT lets me configure the trackpad too.

BetterTouchTool lets you define tons of gestures for your Macbooks Trackpad, your MagicMouse and your MagicTrackpad. In addition to that it brings lots of new stuff to MacOS like Windows 7 like window snapping, window switchers etc…… Extensive explanation is at the BTT developer’s blog. I wanted to add a gesture (four-finger click) to bring up a new Safari window. BTT had Predefined actions to Open Application/File/Script… or Open URL. First of these unfortunately did not open new window, but instead activated one of the pre-existent windows (which I could do just by clicking the Safari Dock icon). The latter did bring up a new window, but I missed the chance to use Top Sites.

AppleScript to the rescue So I typed four lines in AppleScript and now have an action to pop up new Safari window:

tell application "Safari"
    activate
    make new document
end tell

I saved this as an Application to the /Applications folder just for faster startup and pointed BTT Open Application action to that file. Viola!

 

Download Safari New Window