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.
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