• 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: Json
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Json


  • Subject: Re: Json
  • From: Shane Stanley <email@hidden>
  • Date: Wed, 18 Feb 2015 09:34:18 +1100

On 18 Feb 2015, at 3:03 am, Jörgen Stahle <email@hidden> wrote:

Even if I put the handler in a regular scripting library, and call it from another script I'll get the same error when run in Mavericks.

— Script: ---

tell script "f_test" to its convertASToJSON:{a:"b"} saveTo:(missing value) pretty:true
—> error "Can’t get framework \"Foundation\” of «script \"f_test\"». Access not allowed." number -1723 from framework "Foundation"

So you've saved it as a .scptd file in ~/Library/Script Libraries/, yes?

My guess is you saved it running Yosemite, and not Mavericks. In Mavericks, there was a checkbox in Script Editor titled AppleScript/Objective-C Library, which had to be checked. This sets a value in the bundle's Info.plist file, and without it, you get an error like the above.

The good news is that you don't have to do this in Yosemite; the presence of a "use framework..." statement is all that's required to enable AppleScriptObjC. The bad news is that, because of this, the checkbox has been removed from Script Editor, making it harder to save a script library that is backwards compatible. 

Fortunately it's easy enough to modify a bundle's Info.plist file by script -- this simple Yosemite-only droplet will do it:

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

on open fileList
repeat with aFile in fileList
set posixPath to POSIX path of aFile
set anNSURL to (current application's |NSURL|'s fileURLWithPath:posixPath)
if (anNSURL's pathExtension()) as string is "scptd" then
set theInfoNSURL to (anNSURL's URLByAppendingPathComponent:"Contents/Info.plist")
set theInfoDictionary to (current application's NSMutableDictionary's dictionaryWithContentsOfURL:theInfoNSURL)
(theInfoDictionary's setValue:true forKey:"OSAAppleScriptObjCEnabled")
(theInfoDictionary's writeToURL:theInfoNSURL atomically:true)
end if
end repeat
display dialog "Finished." buttons {"OK"} default button 1
end open


…but I just changed the 0 to a 1, and that worked as well.

Enumeration values like NSJSONWritingPrettyPrinted can usually be replaced by their equivalent integers; when you write "current application's NSJSONWritingPrettyPrinted", that's what is returned. It does make you code shorter -- but it also makes it more opaque. So a little extra typing can save you a bit of head-scratching later.


-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
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

References: 
 >Json (From: Jörgen Stahle <email@hidden>)
 >Re: Json (From: Shane Stanley <email@hidden>)
 >Re: Json (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Json
  • Next by Date: Re: Json
  • Previous by thread: Re: Json
  • Next by thread: Re: Json
  • Index(es):
    • Date
    • Thread