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

Oops!


  • Subject: Oops!
  • From: Brian Christmas <email@hidden>
  • Date: Tue, 09 Feb 2016 14:14:25 +1100

G’day Shane

I’ve finally got around to trying to reset my app coding to use your icon setting example, but thought I’d try and modify it slightly, and test it in Vanilla Applescript, but it fails.

What am I doing wrong please?

Regards

Santa

use framework "Foundation"
use framework "AppKit"
use scripting additions


set theApp to "Mail Manager"
my installDockIcon(theApp)

on installDockIcon(theApp)
-- 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:theApp) as boolean
set existsMMDockIcon to my installDockItemsTest(theApp)
if not hasMatch or not existsMMDockIcon then
-- make new tile-data record
set item_path to (path to applications folder as text) & "Mail Manager:" & theApp & ".app" as text
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(theApp)
try
tell application "System Events"
tell process "Dock"
set t to (title of UI elements of list 1)
if theTest contains {theApp} then return true
end tell
end tell
end try
return false
end installDockItemsTest


error "missing value doesn’t understand the “valueForKey_” message." number -1708 from missing value
 _______________________________________________
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: Oops!
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: Setting a .plist value?
  • Next by Date: Re: Oops!
  • Previous by thread: An improved script for Dock Icon Creator
  • Next by thread: Re: Oops!
  • Index(es):
    • Date
    • Thread