• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Acquiring the Dropbox Folder Path -- was: Re: Error -10000 for one user
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Acquiring the Dropbox Folder Path -- was: Re: Error -10000 for one user
      • From: "Stockly, Ed" <email@hidden>
  • Prev by Date: Re: Acquiring the Dropbox Folder Path -- was: Re: Error -10000 for one user
  • Next by Date: Re: Acquiring the Dropbox Folder Path -- was: Re: Error -10000 for one user
  • Previous by thread: Re: Acquiring the Dropbox Folder Path -- was: Re: Error -10000 for one user
  • Next by thread: Re: Acquiring the Dropbox Folder Path -- was: Re: Error -10000 for one user
  • Index(es):
    • Date
    • Thread