set p2Home to path to home folder as text
set p2ApplicationSupport to p2Home & "Library:Application Support:"
set prefName to "DropBoxName"
set prefFile to p2ApplicationSupport & prefName
tell application "System Events"
set prefAvailable to exists file prefFile
end tell
if not prefAvailable then
tell application "System Events"
set DropboxFiles to (name of every folder of p2Home whose name starts with "Dropbox")
end tell
set trueDropbox to choose from list DropboxFiles
if trueDropbox is false then error number -128
set trueDropbox to item 1 of trueDropbox
my writeto(prefFile, trueDropbox, text, false)
else
set trueDropbox to read file prefFile
end if
set p2Dropbox to p2Home & trueDropbox
#=====
(*
*)
on writeto(targetFile, theData, dataType, apendData)
-- targetFile is the path to the file you want to write
-- theData is the data you want in the file.
-- dataType is the data type of theData and it can be text, list, record etc.
-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it
try
set targetFile to targetFile as «class furl»
set openFile to open for access targetFile with write permission
if not apendData then set eof of openFile to 0
write theData to openFile starting at eof as dataType
close access openFile
return true
on error
try
close access targetFile
end try
return false
end try
end writeto
#=====