Quote:
Originally Posted by A to the B
---On a silly XP machine at work, I'll post the script code later---
|
Later...
Code:
on ReplaceText(find, replace, subject)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set subject to text items of subject
set text item delimiters of AppleScript to replace
set subject to "" & subject
set text item delimiters of AppleScript to prevTIDs
return subject
end ReplaceText
--get replaceText("Windows", "the Mac OS", "I love Windows and I will always love Windows and I have always loved Windows.")
tell application "Things"
-- Include date in the filename.
-- Filename will be ThingsToday.2009June5.txt
set {year:y, month:m, day:d} to (current date)
set fileName to "ThingsNext." & y & m & d & ".txt"
-- Set the path. You should replace 'username' with your actual
-- username, and change the path as you please
set pathName to "Macintosh HD:Users:Alan:Desktop:" & fileName
set fullReport to ""
-- To number the lines in the output
set itemCount to 0
repeat with aToDo in to dos of list "Next"
set itemCount to itemCount + 1
-- Create an empty list for tags and notes and well everything...
set allTags to {}
-- Get project name
if (project of aToDo) is not missing value then
set todoDataRow to (name of project of aToDo) & ": " & (name of aToDo) & tab
else
set todoDataRow to "no project" & ": " & (name of aToDo) & tab
end if
-- Get item name
--set todoDataRow to todoDataRow & (name of aToDo) & tab
-- Get all tags on the todo item
set todoTags to tags of aToDo
repeat with aTag in todoTags
copy (name of aTag) to the end of allTags
end repeat
-- Get all tags on the project, if there is one
if (project of aToDo) is not missing value then
set projTags to tags of (project of aToDo)
repeat with aTag in projTags
copy (name of aTag) to the end of allTags
end repeat
end if
-- Get all tags on the area, if there is one --not needed for my application but you may need this
-- if (area of aToDo) is not missing value then
-- set areaTags to tags of (area of aToDo)
-- repeat with aTag in areaTags
-- copy (name of aTag) to the end of allTags
-- end repeat
-- end if
-- Get all notes on the todo, if there is one
if (notes of aToDo) is not missing value then
repeat with x from ((count allTags) + 1) to 4
copy "" to the end of allTags
end repeat
-- Replace line feeds
set aString to ""
copy (notes of aToDo) to aString
copy my ReplaceText("\n", "--- CR GUID ---", aString) to aString
copy aString to the end of allTags
end if
-- Combine the tags (and notes) into a tab-delimited list
if allTags is not missing value then
set AppleScript's text item delimiters to {"\t"}
set todoDataRow to todoDataRow & ¬
(allTags as text)
end if
set fullReport to fullReport & (todoDataRow & return as string)
end repeat
-- Get the count of inbox items
set inboxItems to count of (to dos of list "Inbox")
-- Compile the contexts and notes of the output for this run
-- Include full date and time, and counts of items in Today and Inbox
(* set fullReport to (((the current date) as string) & ¬
(tab as string) & ¬
(tab as string) & ¬
(itemCount as string) & " items in Today, " & ¬
(inboxItems as string) & " items in Inbox" & ¬
return as string) & fullReport & return as string
*)
-- Open and write to the ouput file
set outputFile to open for access (pathName as string) with write permission
write (fullReport & return as string) to outputFile starting at eof
close access outputFile
end tell
It is pretty much a hack of some otherwise nice code written by someone else. I plan to clean up the mess I made :D and alter it to write straight to OF. I am still ramping up on apple script and the syntax...
Script question: Performance wise which is better?
A)
Tell app things to give me a big struct, all at once;
Then tell app OF to parse it and create OF rows all at once;
or B)
For (thisItem in allThingsItems)
{
Tell Things to copy anItem to thisItem;
Tell OF to set thisItem to someNewItem;
}
or C)
is this stuff doable/easier in xcode?
Thanks,
Ab