shortcut to Sourcetree in Mac OS Finder

Drew Dara-Abrams December 4, 2011

Is there an easy way to add a link to the Mac OS Finder toolbar that will open up SourceTree for the current folder (if it contains a git repo)? I've done this with Textmate and the terminal (shown below). The addition of a git GUI would complete the trifecta!

5 answers

2 votes
Mike Brandehorst March 4, 2012

It's simple to make an application with applescript and drop it to the finder toolbar.

on run
	tell application "Finder"
		set theFolder to (the folder of the front window as alias)
		if (exists folder ".git" of theFolder) then
			tell application "SourceTree"
				activate
				open theFolder
			end tell
		end if
	end tell
end run

But every time you get a "want to add to root" question.

Are there commandline options for SourceTree to just open a git folder?

stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 4, 2012

The 'stree' command line tool will open the current directory or any paths it is given on the command line. You can install it using the menu option 'SourceTree > Install Command Line Tools' on the direct download version of SourceTree, or get the supplemental binary for the App Store version from here http://downloads.atlassian.com/software/sourcetree/SourceTreeAppStoreCmdLineToolInstaller.pkg

Mike Brandehorst March 4, 2012
The command-line version:

on run
	tell application "Finder"
		set theFolder to (the folder of the front window as alias)
		if (exists folder ".git" of theFolder) then
			set theFolder to quoted form of POSIX path of (the folder of the front window as alias)
			do shell script "screen -dmS sourcetree-droplet bash -c \"cd " & theFolder & "; /usr/local/bin/stree\""
		end if
	end tell
end run

This still opens "Create Bookmarks?" window.

Mike Brandehorst March 4, 2012

The command-line version:

on run
	tell application "Finder"
		set theFolder to (the folder of the front window as alias)
		if (exists folder ".git" of theFolder) then
			set theFolder to quoted form of POSIX path of (the folder of the front window as alias)
			do shell script "screen -dmS sourcetree-droplet bash -c \"cd " & theFolder & "; /usr/local/bin/stree\""
		end if
	end tell
end run

This still opens "Create Bookmarks?" window.

Mike Brandehorst March 4, 2012
The command-line version:
on run
	tell application "Finder"
		set theFolder to (the folder of the front window as alias)
		if (exists folder ".git" of theFolder) then
			set theFolder to quoted form of POSIX path of (the folder of the front window as alias)
			do shell script "screen -dmS sourcetree-droplet bash -c \"cd " & theFolder & "; /usr/local/bin/stree\""
		end if
	end tell
end run

This still opens "Create Bookmarks?" window.
stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 4, 2012

If you don't have a bookmark for the opened repo then yes, you'll get an option to create a bookmark.

0 votes
Martin Braun May 23, 2021

Here is a good solution that contains an "Open in SourceTree" app that can be dragged and dropped in the toolbar of Finder:

36919049-f5c33b0e-1e81-11e8-9c70-424d2e9ff753

https://github.com/kdabir/finder-buttons

0 votes
stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 4, 2012

In 1.3 if you right-click a folder in Finder and go to 'Services' there is an option 'Open In SourceTree'.

Mike Brandehorst March 4, 2012

True, but three clicks are needed, droplet only one.

0 votes
Mike Brandehorst March 4, 2012

I would like to know this too...

GitX has one, maybe get the sourecode there to build one for SourceTree.

http://code.google.com/p/git-osx-installer/wiki/OpenInGitX

0 votes
Mike Brandehorst March 4, 2012

I would like to know this too...

GitX has one, maybe get the sourecode here to build one for SourceTree:

http://code.google.com/p/git-osx-installer/wiki/OpenInGitX

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events