Re: Acquiring the Dropbox Folder Path -- was: Re: Error -10000 for one user
Re: Acquiring the Dropbox Folder Path -- was: Re: Error -10000 for one user
- Subject: Re: Acquiring the Dropbox Folder Path -- was: Re: Error -10000 for one user
- From: Nigel Garvey <email@hidden>
- Date: Sat, 23 Apr 2016 11:41:53 +0100
"Stockly, Ed" wrote on Fri, 22 Apr 2016 20:46:08 +0000:
>set myPath to path to home folder
>set jsonPath to (myPath as text) & ".dropbox:info.json"
>set dropboxText to read file jsonPath
>set AppleScript's text item delimiters to {"/", "\", \"host\":"}
>set dropboxList to text items of dropboxText
>set AppleScript's text item delimiters to {":"}
>set dropboxPath to {myPath as text}
>set the end of dropboxPath to items 4 thru -2 of dropboxList as text
>set AppleScript's text item delimiters to {""}
>set dropboxPath to dropboxPath as text
>set dropboxPath to dropboxPath as alias
>
>So this works if you have a single dropbox folder. (At least it does on
>multiple users on two of my macs).
>
>Is it possible to have more than one dropbox folder? How does that work?
>What does the info file look like if you have more than one?
I personally only have one Dropbox folder. I've been assuming that
information about any others is stored in the same way in the same .json
file in the same location, that the file's overall data structure is
maintained, and that its text is most wisely interpreted as UTF-8.
Since the data are labelled, it's probably better not to assume anything
about their order except that each value immediately follows its
associated key. So ideally, other keys shouldn't be used as delimiters
when parsing. And since the file contains the full path to the Dropbox
folder, I'd be nervous about assuming the folder was always at the root
level of the user's home folder.
set jsonPath to (path to home folder as text) & ".dropbox:info.json"
set jsonText to (read file jsonPath as «class utf8»)
set astid to AppleScript's text item delimiters
-- Split the text at each "\"path\":" key, ditching the text before the first one.
set AppleScript's text item delimiters to {"\"path\":"}
set dropboxList to rest of jsonText's text items
-- Check the quote-delimited parts of each text item.
set AppleScript's text item delimiters to {"\""}
repeat with thisItem in dropboxList
set dropboxPathParts to {}
repeat with i from 2 to (count thisItem's contents's text items)
set thisPart to text item i of thisItem
if (thisPart ends with "\\") then
-- If a part ends with a backslash, it precedes an escaped quote in the path.
-- Store it without the backslash and go on to the next part.
set end of dropboxPathParts to text 1 thru -2 of thisPart
else
-- Otherwise, this is the whole path or the last part of it.
-- Store it as is and exit the repeat.
set end of dropboxPathParts to thisPart
exit repeat
end if
end repeat
-- Reconstitute the path and replace the text item in dropboxList with the equivalent alias.
set dropboxPath to dropboxPathParts as text
set thisItem's contents to (POSIX file dropboxPath) as alias
end repeat
set AppleScript's text item delimiters to astid
dropboxList
• To be really finicky, one could also check for escaped backslashes in
the path and remove their escaping backslashes.
• While testing, I found that (count thisItem each text item) still
works, although the 'each' parameter hasn't been mentioned in ASLG for
several years. (count thisItem's text items) worked at first, but then
started errorring. Hence the expansion to (count thisItem's contents's
text items) above to resolve thisItem's reference value.
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden