View Full Version : Applescript request - Jump to Project
gcrump
2008-05-18, 07:47 AM
Has anyone written a applescript that will Jump to a specific applescript from either a Launchbar or QS action? What happens to me is that will be in the middle of something else and a thought will occur to me about a particular project. I'd like to pull up launchbar type is a word or two for the project and have a new omnifocus window show up with just this project in it.
Thanks in advance,
George
Craig
2008-05-18, 07:54 PM
I have something almost like that working (though not involving AppleScript). I have created OF perspectives that are focused on my folders (which I treat like "areas of responsbility"). So one called "Focused husband," another "focused teacher," etc. They are set to open as new windows.
Because I have added my perspectives directory (~/Library/Application Support/OmniFocus/Perspectives) to my Quicksilver catalog, I can easily pull them up with a couple of keystrokes to review or add stuff.
gcrump
2008-05-20, 06:23 AM
Craig,
Thanks for the response, but that won't quite do it for me. I tried. I can write the front end interface to capture the text string of the project and I am a so-so applescripter. If someone could show me even a fragment that will take that string and look for a project that contains that string, it might be all I need to complete it.
Thanks again,
George
Ken Case
2008-05-20, 06:42 AM
If someone could show me even a fragment that will take that string and look for a project that contains that string, it might be all I need to complete it.
Try something like this:
set MyProjectArray to complete ProjectString as project maximum matches 1
You can see this in action in the "Send to OmniFocus" sample script inside the application bundle (OmniFocus.app/Contents/Resources/SampleScripts/Send to OmniFocus.applescript).
Hope this helps!
Craig
2008-05-21, 05:20 AM
@ gcrump: if you get this working I hope you share it. It would be one step closer to my fantasy of a Quicksilver plugin for OF (http://forums.omnigroup.com/showthread.php?t=4674).
gcrump
2008-05-21, 07:24 AM
@ Craig - Will do.
@ Ken - I'm stuck and have messed with it all morning. Here is what I have, simple no error handling yet. Not much more than what you gave me. I can't figure out how to pull anything from MyProjectArray. In the Result section of script editor it is setting the variable right. For example if I type in "Spotlight" I get:
{{xml:"Customers : Permabit : Permabit <span class=\"match\">Spotlight</span> Article", score:225, id:"hMhoYt5pZ2e", name:"Customers : Permabit : Permabit Spotlight Article"}}
My assumption is that if I can figure out how to address the array, I can access the ID property and use that to show the Project in a new window. My goal was to add to the script the commands:
set MyProjectID to id of MyProjectArray
set newW to make document window with properties {focus:{MyProjectID}, selected view mode identifier:"project", search term:""}
to the script below. But I get an error on the set MyProjectID statement. If I just use the MyprojectArray in the {focus} I get an error there too...
display dialog "Enter Project to Find" buttons {"Cancel", "Find"} default button 2 default answer "" with title "Project Find"
if button returned of result is "find" then
set ProjectString to text returned of result
tell application "OmniFocus"
set MyDoc to default document
tell MyDoc
set MyProjectArray to complete ProjectString as project maximum matches 1
end tell
end tell
end if
Any help would be appreciated... Thanks.
Ken Case
2008-05-21, 08:55 AM
You're almost there! You just need to pull out the id of the first item in the array, then use that id to look up the project. Like this:
display dialog "Enter Project to Find" buttons {"Cancel", "Find"} default button 2 default answer "" with title "Project Find"
if button returned of result is "find" then
set ProjectString to text returned of result
tell application "OmniFocus"
set MyDoc to default document
tell MyDoc
set MyProjectArray to complete ProjectString as project maximum matches 1
set MyProjectID to id of first item of MyProjectArray
set ThisProject to project id MyProjectID
set newW to make document window with properties {focus:{ThisProject}, selected view mode identifier:"project", search term:""}
end tell
end tell
end if
gcrump
2008-05-21, 12:12 PM
Ken,
Thanks for all the help, well and doing most of the work. What I am struggling with now is to make sure I have the filters set correctly. I figured out how to set the sidebar but I want to show all remaining tasks as well. I think I should use either the set (selected task state filter identifier) to "remaining" statement of the available task state filter but both result in an error...
display dialog "Enter Project to Find" buttons {"Cancel", "Find"} default button 2 default answer "" with title "Project Find"
if button returned of result is "find" then
set ProjectString to text returned of result
tell application "OmniFocus"
set MyDoc to default document
tell MyDoc
set MyProjectArray to complete ProjectString as project maximum matches 1
set MyProjectID to id of first item of MyProjectArray
set ThisProject to project id MyProjectID
set newW to make document window with properties {focus:{ThisProject}, selected view mode identifier:"project", search term:""}
set (selected smart group identifier of sidebar of newW) to "remaining-projects"
-- set (selected task state filter identifier) to "remaining"
end tell
end tell
end if
Thanks again for all your help!
Ken Case
2008-05-21, 01:45 PM
I figured out how to set the sidebar but I want to show all remaining tasks as well. I think I should use either the set (selected task state filter identifier) to "remaining" statement of the available task state filter but both result in an error...
Try this:
set selected task state filter identifier of content of newW to "incomplete"
Glad I could help!
Craig
2008-05-21, 02:40 PM
Very cool! :cool:
I just added an "activate" before the last "end tell"
gcrump
2008-05-21, 07:00 PM
Great Stuff, thanks Ken and Craig
steve
2008-05-26, 07:04 AM
So, is this working now? It sounds like a great idea. I was wondering if someone could copy/paste the code— it seems like there have been a few additions and I'm not quite sure where to add those.
Thanks,
Steve
gcrump
2008-05-26, 07:13 AM
So, is this working now? It sounds like a great idea. I was wondering if someone could copy/paste the code— it seems like there have been a few additions and I'm not quite sure where to add those.
Thanks,
Steve
Steve, yes it is working now. Also I modified it to work with LaunchBar. Here is the code without Launchbar support:
display dialog "Enter Project to Find" buttons {"Cancel", "Find"} default button 2 default answer "" with title "Project Find"
if button returned of result is "find" then
set ProjectString to text returned of result
tell application "OmniFocus"
set MyDoc to default document
tell MyDoc
set MyProjectArray to complete ProjectString as project maximum matches 1
set MyProjectID to id of first item of MyProjectArray
set ThisProject to project id MyProjectID
set newW to make document window with properties {focus:{ThisProject}, selected view mode identifier:"project", search term:""}
set (selected smart group identifier of sidebar of newW) to "remaining-projects"
set selected task state filter identifier of content of newW to "incomplete"
-- set selected task state filter identifier of content of newW to "all"
activate
end tell
end tell
end if
And here it is with Launchbar support...
on handle_string(ProjectString)
if ProjectString is not "" then
tell application "OmniFocus"
set MyDoc to default document
tell MyDoc
set MyProjectArray to complete ProjectString as project maximum matches 1
set MyProjectID to id of first item of MyProjectArray
set ThisProject to project id MyProjectID
set newW to make document window with properties {focus:{ThisProject}, selected view mode identifier:"project", search term:""}
set (selected smart group identifier of sidebar of newW) to "remaining-projects"
set selected task state filter identifier of content of newW to "incomplete"
-- set selected task state filter identifier of content of newW to "all"
activate
end tell
end tell
open location "x-launchbar:hide"
end if
end handle_string
I am going to enhance to accept some parameters like what filter settings to display and thing like that.
Thanks again for all the help.
George
Craig
2008-05-26, 08:45 AM
I also prepended this
tell application "Quicksilver" to activate
to the Quicksilver script, as I was finding that when invoked the script via a Quicksilver trigger, the dialog wouldn't get the focus until I clicked on the bouncing Quicksilver icon in the dock.
I also prepended this
tell application "Quicksilver" to activate
to the Quicksilver script, as I was finding that when invoked the script via a Quicksilver trigger, the dialog wouldn't get the focus until I clicked on the bouncing Quicksilver icon in the dock.
This is happening to me, too, when I try to invoke it using Quicksilver. I don't understand what you mean by prepending it to the Quicksilver script. What Quicksilver script?
Craig
2008-07-01, 07:15 AM
This is happening to me, too, when I try to invoke it using Quicksilver. I don't understand what you mean by prepending it to the Quicksilver script. What Quicksilver script?
I just meant the first script in post #13 immediately above mine. Before the "display dialog..." line, I added "tell application Quicksilver to activate".
steve
2009-10-13, 07:28 PM
Could someone help me figure out what to do with the pasted text. . . I am trying to get it to work with launchbar. Do I save the text as an applescript or something? If you could nudge me in the right direction, I would appreciate it.
Steve
curt.clifton
2009-10-14, 06:34 AM
Steve,
Below is an updated version of the script for LaunchBar. This one displays a dialog box if there are multiple matching projects, letting you choose between them.
To use with LaunchBar you need to:
Launch Script Editor.
Copy the script text into a new script.
Save the script to ~/Library/Scripts/Applications/OmniFocus/FocusOn.scpt
Make sure LaunchBar is configured to index your Scripts directory to arbitrary depth, you may need to go into LaunchBar config and click the Rescan button for Scripts
To trigger the script:
Activate LaunchBar
Type an abbreviation, like 'foc'
Press the space bar to enter text mode
Enter an abbreviation for the project. It should look something like this:
1123
Press the return key
Cheers,
Curt
(* Code due to gcrump (George) on the OF Extras forum.
http://forums.omnigroup.com/showpost.php?p=37275&postcount=13
Updated to handle multiple projects by Curt Clifton.
*)
on run {}
my handle_string("220")
end run
on handle_string(ProjectString)
if ProjectString is not "" then
tell application "OmniFocus"
set MyDoc to default document
tell MyDoc
set MyProjectArray to complete ProjectString as project maximum matches 10
if (count of MyProjectArray) is 0 then
beep
return
else if (count of MyProjectArray) > 1 then
set choices to my getNames(MyProjectArray, {})
set choice to choose from list choices without empty selection allowed
set MyProjectID to my getIDByName(MyProjectArray, item 1 of choice)
else
set MyProjectID to id of first item of MyProjectArray
end if
set ThisProject to project id MyProjectID
set newW to make document window with properties {focus:{ThisProject}, selected view mode identifier:"project", search term:""}
set (selected smart group identifier of sidebar of newW) to "remaining-projects"
set selected task state filter identifier of content of newW to "incomplete"
-- set selected task state filter identifier of content of newW to "all"
activate
end tell
end tell
open location "omnifocus:"
end if
end handle_string
on getIDByName(XMLRecords, theName)
if XMLRecords is {} then
beep
error "No record selected"
end if
set oneName to (name of item 1 of XMLRecords)
log oneName
if oneName is theName then
return id of item 1 of XMLRecords
else
return getIDByName(rest of XMLRecords, theName)
end if
end getIDByName
on getNames(XMLRecords, Accum)
if XMLRecords is {} then
return Accum
else
return getNames(rest of XMLRecords, ({name of (item 1 of XMLRecords)} & Accum))
end if
end getNames
steve
2009-10-14, 09:52 AM
Curt, thank you for explaining how to set this up! That is a great tool. I love it.
gcrump
2009-11-07, 02:44 AM
Curt, Awesome update to the script. Much better application. How Can I get it to only search folder names instead of Project Names?
curt.clifton
2009-11-07, 03:52 AM
George,
OF's complete command that does the search only supports searching for projects and contexts. So searching folder names is a significant change. You'd need to scan through the whole tree under Library looking for folders. (My my Verify Next Actions (http://www.rose-hulman.edu/~clifton/software.html) script has code that could be modified to do that.) Once you found a folder, you'd have to see if it matched the input pattern. Something like name of theFolder contains theSearchPattern would find exact matches, but you wouldn't get the approximate matching that the complete command provides.
Cheers,
Curt
gcrump
2009-11-07, 03:58 AM
Curt, Thanks for the quick reply. Figures it wouldn't be easy :) Oh well I do have your next actions script so I'll work through that. By the way heavy user of your populate template script. Thanks very much for that huge time saver.
curt.clifton
2009-11-14, 10:18 AM
How Can I get it to only search folder names instead of Project Names?
George's idea seemed useful, but adding it to the existing Focus On script was too slow. So, I created a new script "Focus on Folder" that works essentially like the existing one described above, but only searches folder names.
One other difference: the text entered for the search must be appear as contiguous characters in the folder name. That is, a search for “UFO” would match “Documented UFO sightings” but would not match “Founded Ungulates For Obama”. Without a built-in complete command for folder names anything but exact substring matching is too slow.
Here's the new script. Install it and use it like the other one, but call it something different so you can use both scripts.
(*
This script lets you use LaunchBar to open a new OmniFocus window focused on
a folder that matches a given string.
by Curt Clifton, portions derived from code due to gcrump (George) on the
OF Extras forum.
http://forums.omnigroup.com/showpost.php?p=37275&postcount=13
*)
on run {}
my handle_string("374")
end run
on handle_string(FolderString)
if FolderString is not "" then
tell application "OmniFocus"
set mainDoc to default document
set omniFocusFolders to my getFolders(FolderString, mainDoc)
tell mainDoc
if (count of omniFocusFolders) is 0 then
beep
return
else if (count of omniFocusFolders) > 1 then
set choices to reverse of my getNames(omniFocusFolders, {})
set choice to choose from list choices without empty selection allowed
set folderID to my getIDByName(omniFocusFolders, item 1 of choice)
else
set folderID to id of first item of omniFocusFolders
end if
set folderObject to folder id folderID
set newW to make document window with properties {focus:{folderObject}, selected view mode identifier:"project", search term:""}
set (selected smart group identifier of sidebar of newW) to "remaining-projects"
set selected task state filter identifier of content of newW to "incomplete"
-- set selected task state filter identifier of content of newW to "all"
activate
end tell
end tell
open location "omnifocus:"
end if
end handle_string
on getFolders(FolderString, omniFocusDocument)
using terms from application "OmniFocus"
tell omniFocusDocument
set theSections to every section whose class is folder
return my accumulateMatches(FolderString, theSections, {})
end tell
end using terms from
end getFolders
on accumulateMatches(FolderString, theFolders, Accum)
if (theFolders is {}) then
return Accum
end if
return accumulateMatches(FolderString, rest of theFolders, accumulateMatchesHelper(FolderString, item 1 of theFolders, Accum))
end accumulateMatches
on accumulateMatchesHelper(FolderString, aFolder, Accum)
using terms from application "OmniFocus"
if (my matches(name of aFolder, FolderString)) then
set Accum to {aFolder} & Accum
end if
set theSubfolders to every section of aFolder whose class is folder
return accumulateMatches(FolderString, theSubfolders, Accum)
end using terms from
end accumulateMatchesHelper
on matches(folderName, matchString)
return folderName contains matchString
end matches
on getIDByName(XMLRecords, theName)
if XMLRecords is {} then
beep
error "No record selected"
end if
set oneName to (name of item 1 of XMLRecords)
log oneName
if oneName is theName then
return id of item 1 of XMLRecords
else
return getIDByName(rest of XMLRecords, theName)
end if
end getIDByName
on getNames(XMLRecords, Accum)
if XMLRecords is {} then
return Accum
else
return getNames(rest of XMLRecords, ({name of (item 1 of XMLRecords)} & Accum))
end if
end getNames
gcrump
2009-11-15, 01:43 PM
Curt, Great addition to the library. Thanks a ton!
curt.clifton
2010-06-07, 12:48 PM
Bump. (Sorry for the noise, but I spoke with someone today and mentioned this script. I didn't have the URL at hand in the conversation, but said that I'd bump the thread to the top of the forum.)
edwardro
2010-06-07, 01:18 PM
Thanks Curt!!!
I am downloading laundbar now and I will see if there is any documentation in how to install the script there.
THANKS!!!
Edward
RobTrew
2010-06-07, 03:00 PM
FWIW here is the script which I use for refocusing on a particular folder through Launchbar ...
It is a little simpler than Curt's excellent script, but runs very snappily, which reduces a little of the cognitive friction for me ...
(Simply refocuses the current window on the specified folder, and uses a slightly faster approach to find the first folder with a name that contains the substring typed in Launchbar)
(*
Run from Launchbar to refocus current window on a folder
specified by entering a substring of the folder name in Launchbar.
If the script is indexed in and summoned from Launchbar,
tapping spacebar will allow you enter enough of any substring
of the folder name to uniquely identify it.
A simple approach, but runs quite snappily, for those who like that kind of thing :-)
*)
property pstrTitle : "Focus on folder"
on handle_string(strFolderName)
if length of strFolderName > 0 then
tell application id "com.omnigroup.OmniFocus"
set oDoc to default document
set oFolder to my FolderByName(oDoc, strFolderName)
if oFolder is not missing value then
set focus of front document window of oDoc to {oFolder}
else
display dialog "No folder with name containing " & ¬
strFolderName & return & "found in the OF database" with title pstrTitle
end if
activate oDoc
end tell
end if
end handle_string
on FolderByName(oParent, strName)
using terms from application "OmniFocus"
set lstMatches to folders of oParent where name contains strName
if length of lstMatches > 0 then
return first item of lstMatches
else
set lstFolders to folders of oParent
repeat with oFolder in lstFolders
set varResult to FolderByName(oFolder, strName)
if varResult is not missing value then return varResult
end repeat
end if
return missing value
end using terms from
end FolderByName
edwardro
2010-06-07, 04:24 PM
Hi Curt and RobTrew, thanks for the scripts.
The only thing is that for the las 90 minutes I have been searching how to install a script in omnifocus. I found a thread that here that showed me how to get the applescript icon on the SL menubar. I did.
Then to identify my script folder on the ~/scripts/application/ and so on.
Well, I actually called apple care because I did not have a "scripts" folder under my username on my imac. They directed me to hard disk, and there it was.
My next questions are:
1) Will these scripts run well, even if they are not under my username folder, but on the harddiskname/scripts/ and so on?
2) I see that the scripts that both of you are providing are, of course, a code ( a series of instructions ). Am I supposed to saved this as a file or Am I supposed to saved the code on a folder?
My question tells you how new I am on this "scripting business" ;-)
3) I just downloaded launchbar. If there is an easy way to intall this there, please, let me know. I am really confused with this, however, being able to search for a folder is very important for my workflow.
Thank you both for your kind help!!!!
Edward
edwardro
2010-06-07, 04:29 PM
I just found this from Curt:
"Below is an updated version of the script for LaunchBar. This one displays a dialog box if there are multiple matching projects, letting you choose between them.
To use with LaunchBar you need to:
* Launch Script Editor.
* Copy the script text into a new script.
* Save the script to ~/Library/Scripts/Applications/OmniFocus/FocusOn.scpt
* Make sure LaunchBar is configured to index your Scripts directory to arbitrary depth, you may need to go into LaunchBar config and click the Rescan button for Scripts
To trigger the script:
* Activate LaunchBar
* Type an abbreviation, like 'foc'
* Press the space bar to enter text mode
* Enter an abbreviation for the project. It should look something like this:
Click image for larger version Name: Picture 1.png Views: 9 Size: 10.7 KB ID: 1123
* Press the return key
Cheers,
Curt"
I think that answers some of my questions. I will try it to see if it works.
I keep wondering if there is any difference to run the scrips from my harddisk as opposed from my username folder.
Thanks,
Edward
RobTrew
2010-06-07, 07:57 PM
I keep wondering if there is any difference to run the scripts from my harddisk as opposed from my username folder.
Script behaviour is not affected by the location of the script file, but placing it in a folder like [Your UserName]/Library/Scripts/Applications/OmniFocus does have the advantage that the script will then appear in the OmniFocus scripts menu, and can easily be installed on your toolbar.
There is a summary of script installation in another thread (http://forums.omnigroup.com/showthread.php?t=7453).
RobTrew
2010-06-07, 10:48 PM
For reference, here is the LaunchBar script which I use for focusing on Projects whose names contain a string entered at the Launchbar prompt.
Its a quick and simple approach, which just refocuses the current window on any projects (up to a maximum number) whose names contain the entered string.
Useful to me as I often have a small group of projects with related names.
(*
Run from Launchbar to refocus current window on any projects
whose names match a sub-string entered in Launchbar.
If the script is indexed in and summoned from Launchbar,
tapping spacebar will allow you enter enough of any substring
of a project name to uniquely identify it.
If the string entered turns out not to be unique,
then a list of candidate projects will get the focus in the current window.
(Useful to me as I often have a small set of projects with related names)
*)
property pstrTitle : "Focus on project"
property pmaxProjCount : 10
on handle_string(strprojectName)
if length of strprojectName > 0 then
tell application id "com.omnigroup.OmniFocus"
set oDoc to default document
set lstprojects to my ProjectsByName(oDoc, strprojectName)
if lstprojects is not missing value then
set focus of front document window of oDoc to lstprojects
else
display dialog "No projects with name containing " & return & return & ¬
tab & quote & strprojectName & quote & return & return & ¬
"found in the OF database" with title pstrTitle
end if
activate oDoc
end tell
end if
end handle_string
on ProjectsByName(oDoc, strName)
using terms from application "OmniFocus"
tell oDoc
set lstMatches to (complete strName as project ¬
maximum matches pmaxProjCount)
if length of lstMatches > 0 then
set lstprojects to {}
repeat with recMatch in lstMatches
set end of lstprojects to project id (id of recMatch)
end repeat
return lstprojects
else
return missing value
end if
end tell
end using terms from
end ProjectsByName
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.