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