AppleScript to export all Stickies to text files

I was looking for a way to put my Mac Stickies on my Android phone, as as the first solution, I just save the text of all the stickies into a bunch of text files that I can then copy to the phone.

To save the stickies on OSX Lion, I found an AppleScript script that does that, except it has problems with double quotes in the stickies, so I tweaked it, see below.

One remaining limitation is that it can't handle spaces, so I run the script manually on every space that has some stickies on it - the script creates new files for all the stickies. This also means that if you already saved some stickies and you rerun the script on the same screen, you'll get duplicates. If you know how to fix the access to stickies on all spaces, please let me know.

Here's the script:

set theName to ""
set i to 0
set n to {}
set L to {}
set destFldr to ""
set mydestFldr to ""
if destFldr = "" then
	set destFldr to (choose folder with prompt "Choose a destination folder:") as text
	set mydestFldr to POSIX path of destFldr
end if
tell application "Stickies"
	activate
	tell application "System Events"
		tell application process "Stickies"
			set L to name of windows
			try
				repeat with awindow in L
					set m to value of text area 1 of scroll area 1 of window awindow
					set end of n to m
				end repeat
			end try
			repeat with acontent in n
				repeat
					set i to i + 1
					set theName to mydestFldr & "stickies" & "_" & (i as string) & ".txt"
					set existsFlag to ""
					tell application "Finder" to if exists theName as POSIX file then set existsFlag to "yes"
					if (existsFlag = "") then exit repeat
				end repeat
				try
					set theFileReference to open for access theName with write permission
					write acontent to theFileReference
					close access theFileReference
				end try
			end repeat
		end tell
	end tell
	tell application "Finder"
		activate
		open destFldr
	end tell
end tell
Posted at 1548 on Tue, Nov 1, 2011 in category Work | TrackBack | Comments feed
Comments
Post a comment



(will not be published)





Remember personal info?