Re: Acquiring the Dropbox Folder Path -- was: Re: Error -10000 for one user (Nigel Garvey)
Re: Acquiring the Dropbox Folder Path -- was: Re: Error -10000 for one user (Nigel Garvey)
- Subject: Re: Acquiring the Dropbox Folder Path -- was: Re: Error -10000 for one user (Nigel Garvey)
- From: Nigel Garvey <email@hidden>
- Date: Sun, 24 Apr 2016 16:51:29 +0100
Olof Hellman wrote on Sat, 23 Apr 2016 12:57:17 -0700:
>One can have multiple Dropbox folders if you have an email address
>associated with a “Dropbox Business” account and also a separate
>personal email associated with a regular Dropbox account (Pro or Basic).
>
>One of your Dropbox folders is called “Dropbox (Personal)” and the other
>is called “Dropbox (<BusinessName>)”. The json file is what you
>expect: If you worked at Cupcake Corporation and you had your Cupcake
>Corporation Dropbox linked to your computer, the file would look like:
>
> {
> "personal":
> {
> "path": "/Users/ed/Dropbox (Personal)",
> "host": 1234567890,
> "is_team": false,
> "subscription_type": "Pro"
> },
> "business":
> {
> "path": "/Users/ed/Dropbox (Cupcake Corporation)",
> "host": 1234509876,
> "is_team": true,
> "subscription_type": "Business"
> }
>}
Thanks, Olof. So if I've read you correctly and one is limited to one
personal Dropbox and/or one for a business, the POSIX paths to them both
— or a path and a missing value — can be obtained reasonably tersely
like this:
set {personal:{|path|:personalDropboxPath}, business:{|path|:businessDropboxPath}} to (run script (do shell script "cat ~/.dropbox/info.json | sed -E 's/\"([[:alnum:]_]+)\":/|\\1|:/g'")) & {personal:{|path|:missing value}, business:{|path|:missing value}}
return {personalDropboxPath, businessDropboxPath}
--> eg. {"/Users/ed/Dropbox", missing value}
If my regex isn't trusted, or a more flexible approach is needed, the
following uses official means to extract the information and returns a
list of locations for Dropboxes which actually exist (or which have
entries in the json file, anyway). Each "location" is a sublist
containing the key used in the json and an alias to the folder itself.
use framework "Foundation"
set jsonPath to "~/.dropbox/info.json"
--set jsonPath to "~/Desktop/Dropbox test info.json"
set jsonFullPath to (current application's class "NSString"'s stringWithString:jsonPath)'s stringByExpandingTildeInPath()
set jsonData to current application's class "NSData"'s dataWithContentsOfFile:((current application's class "NSString"'s stringWithString:jsonPath)'s stringByExpandingTildeInPath())
-- Make an ObjC dictionary from the json data.
set dataDict to current application's class "NSJSONSerialization"'s JSONObjectWithData:jsonData options:0 |error|:(missing value)
set dropboxLocations to {}
repeat with thisKey in dataDict's allKeys()
set end of dropboxLocations to {thisKey as text, ((dataDict's objectForKey:thisKey)'s objectForKey:"path") as «class furl» as alias}
end repeat
return dropboxLocations
--> eg. {{"personal", alias "Macintosh HD:Users:ed:Dropbox (Personal)"}, {"business", alias "Macintosh HD:Users:ed:Dropbox (Cupcake Corporation)"}}
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