Skip to content

Instantly share code, notes, and snippets.

@ROldford
Last active December 19, 2015 10:39
Show Gist options
  • Save ROldford/5941579 to your computer and use it in GitHub Desktop.
Save ROldford/5941579 to your computer and use it in GitHub Desktop.
A TaskPaper script that can be used to move archived tasks to a timestamped file for storage. Go to http://www.hogbaysoftware.com/wiki/MoveArchiveToFile for more information.
(*
Move Archive to File script
by Ryan Oldford
handlers adapted from MacScripter (http://macscripter.net/viewtopic.php?id=24737)
This script is used with TaskPaper to move archived tasks in a document to archive
files for future reference.
The files are stored in a user-specified Archive directory within the TaskPaper directory,
and are given a timestamp in their filenames.
The script settings can be edited to match your TaskPaper folder locations and preferences
for the archive filenames.
Settings:
taskpaperPathName - the path to your Taskpaper directory
archiveFolderName - the name of the folder where the archive files will be stored
ArchivePrefix - what the beginning of the archive file's filename should be (before the timestamp)
*)
property taskpaperPathName : (((path to home folder) as text) & "Dropbox:TaskPaper:")
property archiveFolderName : "Archives"
property archivePrefix : "Archive - "
set archivesPathName to taskpaperPathName & archiveFolderName & ":"
set taskpaperPath to taskpaperPathName as alias
set todaysTimeStamp to timeStamp(current date)
set archiveFileName to archivePrefix & todaysTimeStamp & ".taskpaper"
set archiveFileNameWithPath to archivesPathName & archiveFileName
tell application "TaskPaper"
activate
set docName to the name of document 1
end tell
tell application "Finder"
set folderExists to exists (archivesPathName)
if not folderExists then
activate
display dialog "No Archives folder found in Taskpaper directory. Please make one." buttons {"OK"} default button 1
else
set archivesPath to archivesPathName as alias
make new file at archivesPath with properties {name:archiveFileName, extension hidden:false}
tell application "TaskPaper"
activate
open archiveFileNameWithPath
set newArchiveDoc to the name of document 1
move entries of project named "Archive" of document named docName to end of entries of document named newArchiveDoc
save document named newArchiveDoc
close document named newArchiveDoc
end tell
end if
end tell
to timeStamp(theDate) -- theDate must be date object
set separator to "-" -- can be changed to whatever you prefer
set y to year of theDate
set m to month of theDate
set d to day of theDate
set t to time of theDate
set dateNumber to (y * 10000 + m * 100 + d)
set tempDateString to dateNumber as string
set dateString to text 1 thru 4 of tempDateString & separator & text 5 thru 6 of tempDateString & separator & text 7 thru 8 of tempDateString & separator & t
return dateString
end timeStamp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment