À la bonne Sainte-Force

Tools

Tags

Switching between current projects

19 July 2012

Dear friend,

The Porkcut of the day is about switching between current projects. Basically, it adds a submenu intelligently called Current projects that lists your current projects, and from where you can jump to any of them. What's a current project, you ask ? For this Porkcut, it's just something in a special folder (in my version, the folder is called Zzz_Current, but it can be different for you). When you jump to a project using this Porkcut, it just opens that something in the special folder. It can be a folder, an alias to another folder, an application, a tin can or even a multiplexer. I find it useful to put some aliases and tin cans to my most active projects.

The best place to put this Porkcut is a folder in which you store all your projects. Let's call this folder Projects. Once you've installed that Porkcut, make sure you create the special current projects folder just in Projects. In my computer, the Porkcut is in the file Projects/Porkcuts.fscript, and the current project folder is Projects/Zzz_Current. It's a weird name, but it's made purposefully, to ensure that the folder is the last of the list.

"Current Projects"
menu := NSMenu alloc initWithTitle:'Current projects'.
currentProjectsFolderName := 'Zzz_Current'. "<-- Customize this line."
currentProjectsPath := (((Pork cuts currentDirectoryURL) path) stringByAppendingPathComponent:currentProjectsFolderName).
(NSFileManager defaultManager contentsOfDirectoryAtPath:currentProjectsPath error:nil) do:[ :e |
	item := NSMenuItem alloc init.
	item setTitle:e.
	item setAction:#value:.
	item setKeyEquivalent:(e substringWithRange:(NSValue rangeWithLocation:0 length:1)).
	item setKeyEquivalentModifierMask:0.
	item setTarget:[ :sender |
		NSWorkspace sharedWorkspace openFile:(currentProjectsPath stringByAppendingPathComponent:e)
	].
	menu addItem:item.
].
item := NSMenuItem alloc init.
item setTitle:'Current projects'.
item setTarget:[ :sender | 
	NSWorkspace sharedWorkspace openFile:currentProjectsPath
].
item setAction:#value:.
item setSubmenu:menu.
Pork cuts menu addItem:item.
Switch between current projects and be happy

As a special bonus, it also creates key equivalents for the folder names, so that you can navigate really swiftly.

Looking forward to hearing from you,
Hubert Sainte-Force