• 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: Mavericks AppleScript Editor formatting problems redux
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mavericks AppleScript Editor formatting problems redux


  • Subject: Re: Mavericks AppleScript Editor formatting problems redux
  • From: Shane Stanley <email@hidden>
  • Date: Mon, 11 Nov 2013 10:22:28 +1100

On 11 Nov 2013, at 9:08 AM, Robert Poland <email@hidden> wrote:

All carefully encoded in gibberish.

You were correct with the first three words. It's a file meant to be read by machines, not people, and it's encoded accordingly. Property list files won't store fonts and colors any other way.

And those who like to dabble in editing preference files should take heed of Bill Cheeseman's comments.

That notwithstanding, most of us have machines in front of us, and many are running Mavericks. That means we can read this "gibberish" with AppleScript.

Save this file as .scpt file in ~/Library/Script Libraries, and call it "Read AS styles.scptd". When you've saved it, click on the Bundle Contents button in the toolbar, click on the AppleScript Objective-C library button, and save it again:

use framework "Foundation"
on doIt()
-- get the info as a dictionary
set thePath to current application's NSString's stringWithString:"~/Library/Preferences/com.apple.applescript.plist"
set thePath to thePath's stringByExpandingTildeInPath()
set theInfo to current application's NSDictionary's dictionaryWithContentsOfFile:thePath
-- extract relevant part and loop through
set theArray to (theInfo's valueForKey:"AppleScriptSourceAttributes") as list
repeat with i from 1 to count of theArray
set anEntry to item i of theArray
set colorData to NSColor of anEntry
-- convert "gibberish" to a color
set theColor to (current application's NSUnarchiver's unarchiveObjectWithData:colorData)
-- get values from color
log ({redValue:theColor's redComponent(), greenValue:theColor's greenComponent(), blueValue:theColor's blueComponent()})
set fontData to NSFont of anEntry
-- convert "gibberish" to a font
set theFont to (current application's NSUnarchiver's unarchiveObjectWithData:fontData)
-- get values from font
log ({fontName:theFont's displayName() as text, fontSize:theFont's pointSize()})
end repeat
end doIt

Open a new script window and run this:

use theLib : script "Read AS styles"
theLib's doIt()

Look at the log:

(*redValue:0.500007629395, greenValue:0.0, blueValue:0.500007629395*)
(*fontName:Menlo Regular, fontSize:12.0*)
(*redValue:0.0, greenValue:0.0, blueValue:0.0*)
(*fontName:Verdana, fontSize:12.0*)
(*redValue:0.0, greenValue:0.0, blueValue:0.0*)
(*fontName:Verdana Bold, fontSize:12.0*)
(*redValue:0.0, greenValue:0.0, blueValue:1.0*)
(*fontName:Verdana, fontSize:12.0*)
(*redValue:0.299992382526, greenValue:0.30457007885, blueValue:0.30457007885*)
(*fontName:Verdana, fontSize:12.0*)
(*redValue:0.0, greenValue:0.0, blueValue:0.0*)
(*fontName:Verdana, fontSize:12.0*)
(*redValue:0.250003814697, greenValue:0.500007629395, blueValue:0.0*)
(*fontName:Verdana, fontSize:12.0*)
(*redValue:0.0, greenValue:0.0, blueValue:0.0*)
(*fontName:Verdana, fontSize:12.0*)
(*redValue:0.0, greenValue:0.0, blueValue:1.0*)
(*fontName:Verdana Bold, fontSize:12.0*)
(*redValue:0.0, greenValue:0.0, blueValue:1.0*)
(*fontName:Verdana, fontSize:12.0*)
(*redValue:0.0, greenValue:0.0, blueValue:1.0*)
(*fontName:Verdana Italic, fontSize:12.0*)
(*redValue:0.423366695642, greenValue:0.018407246098, blueValue:0.828326165676*)
(*fontName:Verdana, fontSize:12.0*)
(*redValue:0.423366695642, greenValue:0.018407246098, blueValue:0.828326165676*)
(*fontName:Verdana Italic, fontSize:12.0*)
(*redValue:0.0, greenValue:0.086564429104, blueValue:0.689860403538*)
(*fontName:Verdana Bold, fontSize:12.0*)
(*redValue:0.0, greenValue:0.086564429104, blueValue:0.689860403538*)
(*fontName:Verdana, fontSize:12.0*)
(*redValue:0.0, greenValue:0.086564429104, blueValue:0.689860403538*)
(*fontName:Verdana Italic, fontSize:12.0*)
(*redValue:0.265522241592, greenValue:0.082642860711, blueValue:0.69161516428*)
(*fontName:Verdana, fontSize:12.0*)
(*redValue:0.265522241592, greenValue:0.082642860711, blueValue:0.69161516428*)
(*fontName:Verdana Italic, fontSize:12.0*)


-- 
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: 
 >Re: Mavericks AppleScript Editor formatting problems redux (From: email@hidden)
 >Re: Mavericks AppleScript Editor formatting problems redux (From: "Manoah F. Adams" <email@hidden>)
 >Re: Mavericks AppleScript Editor formatting problems redux (From: Robert Poland <email@hidden>)

  • Prev by Date: Re: Mavericks AppleScript Editor formatting problems redux
  • Next by Date: Re: Universal Scripts Backup
  • Previous by thread: Re: Mavericks AppleScript Editor formatting problems redux
  • Next by thread: Re: Mavericks AppleScript Editor formatting problems redux
  • Index(es):
    • Date
    • Thread