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: Fri, 22 Apr 2016 20:55:33 +0100
Christopher Stone wrote on Fri, 22 Apr 2016 11:03:32 -0500:
>Yes, there are quite a few way to skin that cat. :)
>
>Using the Satimage.osax:
>
>set dropBoxPaths to find text "/[^\"]+" in (readtext
>"~/.dropbox/info.json") with regexp, all occurrences and string result
Yes. That's probably what I'd use myself if I knew the user's machine
had Satimage. :) But I might expand it to cope with the distant
possibility of quotes in the paths(s):
set dropBoxPaths to (change "\\" into "" in (find text "/([^\\\\\"]|\\\\\")+" in (readtext "~/.dropbox/info.json") with regexp, all occurrences and string result))
My earlier ASObjC effort allowed for the possibility of quotes, but
neglected to reduce the number of escape characters in the results.
Here's another go at it. The extra step to delete the escapes allows the
incidental linefeeds at the beginning and end to go at the same time.
use framework "Foundation"
set jsonPath to "~/.dropbox/info.json"
tell current application's class "NSString"
set jsonFullPath to (its stringWithString:jsonPath)'s stringByExpandingTildeInPath()
set jsonText to its stringWithContentsOfFile:jsonFullPath encoding:(current application's NSUTF8StringEncoding) |error|:(missing value)
end tell
set usingRegex to current application's NSRegularExpressionSearch
set dropboxPaths to (jsonText's stringByReplacingOccurrencesOfString:"(^|(?<!\\\\)\")[^/]+" withString:linefeed options:usingRegex range:{0, jsonText's |length|()})
set dropboxPaths to dropboxPaths's stringByReplacingOccurrencesOfString:"\\\\|\\A[[:cntrl:]]|[[:cntrl:]]\\Z" withString:"" options:usingRegex range:{0, dropboxPaths's |length|()}
set dropboxPaths to paragraphs of (dropboxPaths as text)
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