• 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: Setting a .plist value?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setting a .plist value?


  • Subject: Re: Setting a .plist value?
  • From: Brian Christmas <email@hidden>
  • Date: Sun, 07 Feb 2016 21:33:22 +1100

Shane, my apologies. I’d only just got back from a trip to Ballarat, during which I realised I’d posted with two bugs, and didn’t check my email before editing and re-posting.

Your version is so much more Elegant than my latest try. Thank you.

At least the code works, to my relief. Having either no icon (if the user dragged it off), or multiple icons, was driving me crazy. I HATE it when something doesn’t work right.

Regards

Santa


On 7 Feb 2016, at 2:05 PM, Shane Stanley <email@hidden> wrote:

On 7 Feb 2016, at 10:18 AM, Brian Christmas <email@hidden> wrote:

Code is (for posterity)…

Let's see if we can clean it up a bit first...

on installDockIcon()
-- get the info we need
set defaultsObject to current application's NSUserDefaults's alloc()'s init()
set theInfoRecord to (defaultsObject's persistentDomainForName:"com.apple.dock")
set persistentAppsArray to theInfoRecord's objectForKey:"persistent-apps"
set tileDataArray to persistentAppsArray's valueForKey:"tile-data"
set theLabels to tileDataArray's valueForKey:"file-label"
-- check for match
set hasMatch to (theLabels's containsObject:"Mail Manager") as boolean
set existsMMDockIcon to my installDockItemsTest()
if not hasMatch or not existsMMDockIcon then
-- make new tile-data record
set item_path to (path to applications folder as text) & "Mail Manager:Mail Manager.app"
set item_path to POSIX path of item_path
set newValue to {|file-data|:{_CFURLString:item_path, _CFURLStringType:0}}
-- add it to the old tile-data array
set tileDataArray to tileDataArray's arrayByAddingObject:newValue
-- add new tile-data array to the persistent-apps array
set persistentAppsArray to persistentAppsArray's arrayByAddingObject:tileDataArray
-- update theInfoRecord with the new persistent-apps array
set theInfoRecordNew to (theInfoRecord's mutableCopy()) -- make mutable copy so you can change it
theInfoRecordNew's setObject:persistentAppsArray forKey:"persistent-apps"
-- store the new value
defaultsObject's setPersistentDomain:theInfoRecordNew forName:"com.apple.dock"
tell application "Dock" to quit
end if
end installDockIcon

on installDockItemsTest()
try
tell application "System Events"
tell process "Dock"
set t to (title of UI elements of list 1)
if theTest contains {"Mail Manager"} then return true
end tell
end tell
end try
return false
end installDockItemsTest

-- 
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: Setting a .plist value? (From: Brian Christmas <email@hidden>)
 >Fwd: Setting a .plist value? (From: Brian Christmas <email@hidden>)
 >Re: Setting a .plist value? (From: David Gregg <email@hidden>)
 >Re: Setting a .plist value? (From: Brian Christmas <email@hidden>)
 >Re: Setting a .plist value? (From: Shane Stanley <email@hidden>)

  • Prev by Date: An improved script for Dock Icon Creator
  • Next by Date: Oops!
  • Previous by thread: Re: Setting a .plist value?
  • Next by thread: An improved script for Dock Icon Creator
  • Index(es):
    • Date
    • Thread