hi
I have failed to adapt the Applescript below to work with BBEdit, with a .taskpaper extension (I use TaskPaper BBEdit module: http://tinyurl.com/yrabuqt).
It allows user to quickly Append a text to a single document storing multiple tasks, using Quicksilver to trigger script, with Growl notification.
It also looks for listed Projects to choose from, which back on BBEdit are Symbol. This part of the script, while very handy, is not a priority for me. But a solution would be very useful!
Applescript:
xxxxxxxxxxxxxxxxxxxxxxxx
property documentName : “$.taskpaper”
property documentPath : “Mac:Users:X:Documents:$.taskpaper”
– the name of the default project that new tasks get added to
property inboxName : “inbox”
using terms from application “Quicksilver”
on process text inputString
my processLauncherInput(inputString)
end process text
end using terms from
on processLauncherInput(inputString)
try
– remember currently active app, so that we can return focus to it at the end
set lastApp to (path to frontmost application as string)
– figure out if TaskPaper was hidden (so we can hide it again at the end)
tell application “System Events”
set TPwasAlreadyRunning to (count (every process whose name is “TaskPaper”)) = 1
if TPwasAlreadyRunning then
set was_visible to visible of process “TaskPaper”
else
tell application “TaskPaper” to run
set was_visible to true
end if
set growlIsRunning to (count of (every process whose name is “GrowlHelperApp”)) > 0
end tell
try
tell application "TaskPaper" to set theDoc to document documentName
on error
-- try to open the specified document
try
tell application "Finder"
open file documentPath
end tell
if TPwasAlreadyRunning then
delay 2 -- wait a couple of seconds for TaskPaper to load the document
else
delay 6 -- wait a few seconds for TaskPaper to actually start up and load the document
end if
end try
end try
tell application "TaskPaper"
-- try to access the document with the specified name
set openDocs to name of documents
if openDocs contains documentName then
set theDoc to document documentName
else if (count of openDocs) = 1 then
set theDoc to first document
else if (count of openDocs) > 1 then
activate
set choice to (choose from list openDocs default items (item 1 of openDocs) ¬
with prompt "Choose document" without multiple selections allowed)
if choice is not false and (count of choice) > 0 then
set theDoc to document (item 1 of choice)
else
return
end if
else
display alert "Sorry. I could not find a TaskPaper document to add your new task to." & return & ¬
"Either edit the path to your document in the script or manually open the document " & ¬
"in TaskPaper before using this Quicksilver script."
return
end if
set fullText to the text contents of theDoc
end tell
-- parse the input into task and project
set projectName to inboxName -- default if nothing else gets specified
if inputString contains ":" then
set projTaskDict to my splitInput(inputString)
set taskText to taskText of projTaskDict
if length of projectName of projTaskDict > 0 then
set projectName to projectName of projTaskDict
else
set myProjects to my getProjects(fullText)
if (count of myProjects) = 1 then
set projectName to item 1 of myProjects
else if (count of myProjects) > 1 then
set defaultSelection to item 1 of myProjects
tell application "TaskPaper"
activate
set choice to (choose from list myProjects default items defaultSelection ¬
with prompt "Choose project" without multiple selections allowed)
end tell
if choice is false or length of choice = 0 then
return
else
set projectName to item 1 of choice
end if
end if
end if
set taskText to taskText of projTaskDict
else
set projectName to inboxName
set taskText to inputString
end if
set projectLabel to projectName & ":"
-- insert the task into the appropriate Project
if fullText contains projectLabel then
set newText to my replaceText(fullText, projectLabel, projectLabel & return & "- " & taskText)
else -- if the Project doesn't exist yet, add it to the beginning of the file
set newText to projectLabel & return & "- " & taskText & return & fullText
end if
tell application "TaskPaper"
set the text contents of theDoc to newText
end tell
-- hide Taskpaper again if it was hidden before
if was_visible is false then
tell application "Finder"
set visible of process "TaskPaper" to false
end tell
end if
tell application lastApp to activate
-- try to send a Growl notification
if growlIsRunning then
try
growlNotify(taskText, projectName)
end try
end if
-- if we get an unhandled error along the way, show dialog box with message
on error errMsg
tell application "Finder"
display alert ("Unexpected error: " & errMsg)
end tell
end try
end processLauncherInput
on splitInput(inputText)
set theOffset to offset of “:” in inputText
if theOffset is 1 then
set projectName to “”
else
set projectName to text 1 thru (theOffset - 1) of inputText
end if
set taskText to text (theOffset + 1) thru -1 of inputText
repeat while taskText starts with " "
set taskText to text 2 thru -1 of taskText
end repeat
return {projectName:projectName, taskText:taskText}
end splitInput
on getProjects(docText)
set projectNames to {}
repeat with p in paragraphs of docText
if isProject(p) then
set projectNames to projectNames & text 1 thru ((offset of “:” in p) - 1) of p
end if
end repeat
return projectNames
end getProjects
on isProject(textLine)
ignoring white space
return textLine ends with “:” and textLine does not start with “-”
end ignoring
end isProject
on growlNotify(task, project)
tell application “GrowlHelperApp”
register as application “TaskPaper QS script” all notifications {“Task added”} ¬
default notifications {“Task added”} icon of application “TaskPaper.app”
notify with name ¬
“Task added” title “New task added” description task & return & ¬
“added to "” & project & “" project” application name “TaskPaper QS script”
end tell
end growlNotify
on replaceText(theText, SearchString, ReplaceString)
set OldDelims to AppleScript’s AppleScript’s text item delimiters
set AppleScript’s AppleScript’s text item delimiters to SearchString
set newText to text items of theText
set AppleScript’s AppleScript’s text item delimiters to ReplaceString
set newText to newText as text
set AppleScript’s AppleScript’s text item delimiters to OldDelims
return newText
end replaceText
xxxxxxxxxxxxxxxxxxxxxxxx
Note: I am not the author of this script, signed by Wysewoman on HogBay site