Skip to content

Instantly share code, notes, and snippets.

@danmackinlay
Created March 5, 2010 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danmackinlay/322512 to your computer and use it in GitHub Desktop.
Save danmackinlay/322512 to your computer and use it in GitHub Desktop.
-- invoke with $ osascript ensure_mate.scpt /path/to/project
-- or create a wrapper script that looks like this:
-- #!/bin/sh
-- osascript ~/bin/ensure_mate.scpt $@ &
-- Created 2010 Dan MacKinlay and hereby released into the public domain
on run (wantedPath)
set wantedPathFound to false
global wantedDoc
tell application "TextMate"
set allDocs to documents
repeat with doc in allDocs
if path of doc exists then -- beware unsaved files!
set docPath to path of doc
-- "starts with" because we assume we are opening a folder
if docPath starts with wantedPath then
set wantedPathFound to true
set wantedDoc to doc
end if
end if
end repeat
if wantedPathFound then
-- this branch should bring the folder window to the front if already open
-- doesn't work - window has no document, for some reason
-- see http://lists.macromates.com/textmate/2009-March/028352.html
local currDoc
repeat with wind in (get every window)
if document of wind exists then
set currDoc to (get first document of wind)
if currDoc is wantedDoc then
set index of wind to 1
end if
end if
end repeat
else
-- elsewise just open it
open wantedPath
end if
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment