Skip to content

Instantly share code, notes, and snippets.

Forked from danmackinlay/ensure_mate.scpt
Created March 15, 2010 15:04
Show Gist options
  • Save zzot/332920 to your computer and use it in GitHub Desktop.
Save zzot/332920 to your computer and use it in GitHub Desktop.
Actually, you can use the standard UNIX interpreter syntax directly with osascript; just mark the file as executable and you're set.
-- 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
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
-- 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