• 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
An improved script for Dock Icon Creator
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

An improved script for Dock Icon Creator


  • Subject: An improved script for Dock Icon Creator
  • From: Brian Christmas <email@hidden>
  • Date: Sun, 07 Feb 2016 21:23:45 +1100

G’day scripters.

for Google search...

Applescript Dock Icon Creator

This morning, before I had several hours cat-nap,  I inadvertently posted a version of my script that was partially lifted from my test Applescript, instead of from my App, and the App version had two bug fixes.

So, for those interested, and for posterity, here’s a full Applescript, improved version of my Applescript version. Note my Application path, (item_path), includes a folder within the Applications Folder in my case.

Regards

Santa

use AppleScript version "2.4"
use framework "Foundation"
use framework "AppKit"
use scripting additions

my installDockIcon("Mail Manager")

on installDockIcon(theApp)
try
set item_path to ((path to applications folder) & "Mail Manager:" & theApp & ".app" as text) # NOTE: my App is in a folder called 'Mail Manager'
end try
try


set theInfo to (current application's NSUserDefaults's alloc()'s init()'s persistentDomainForName:"com.apple.dock") as record
set theMatches to get theInfo's |persistent-apps|
set MatchingList to {}
set x to 0
repeat with thisRecord in theMatches
set x to x + 1
set theTestMatch to get thisRecord's |tile-data|
set theMMMatch to theTestMatch's |file-label|
if theMMMatch as text is theApp then
set end of MatchingList to item x of theMatches
end if
end repeat
set existsMMDockIcon to my installDockItemsTest(theApp)
if (count of MatchingList) < 1 or not existsMMDockIcon then
try
set item_path to POSIX path of item_path
do shell script "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & item_path & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
tell application "Dock" to quit # Automatically re-starts
end try
end if
end try
end installDockIcon

on installDockItemsTest(theApp)
set x to 1
try
tell application "System Events"
tell process "Dock"
set t to (title of UI elements of list 1)
set x to 0
repeat with theTest in t
if theTest as text = theApp then set x to x + 1
end repeat
end tell
end tell
end try
return (x > 0)
end installDockItemsTest

 _______________________________________________
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

  • Prev by Date: Re: Setting a .plist value?
  • Next by Date: Re: Setting a .plist value?
  • Previous by thread: Re: Setting a .plist value?
  • Next by thread: Oops!
  • Index(es):
    • Date
    • Thread