KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Programatically creating a Dock icon
PRODUCT: 4D | VERSION: 2004 | PLATFORM: Mac OS X
Published On: October 30, 2006

Here is a method that will create an icon in the Dock for the passed application bundle:

` ---------------------------------------------------
` Project method: AddToDock
` Example: AddToDock("myApp";"/Applications/myApp.app")
` ---------------------------------------------------
` Programmer: Jeremy Sullivan
` Created: Mon, Mar 13, 2006 8:00 AM
` ---------------------------------------------------
` Description: Adds an application to the Dock on Mac OS X
` ---------------------------------------------------
` Parameters
`   Passed:
`   $1 TEXT - Application name as it should appear in the Dock
`   $2 TEXT - Posix path to the application bundle (don't forget the .app)
` Returned:
` ---------------------------------------------------
` Calls:
` Called By:
` ---------------------------------------------------

C_TEXT($1;$2;$applicationName_t;$applicationPath_t)
C_TEXT($command_t;$inputStream_t;$outputStream_t;$errorStream_t)

$applicationName_t:=$1 ` myApp
$applicationPath_t:=$2 ` must be a posix path (/Applications/myApp.app)

$command_t:="defaults write com.apple.dock persistent-apps -array-add "
$command_t:=$command_t+"'tile-data"
$command_t:=$command_t+"file-data"
$command_t:=$command_t+"_CFURLString"
$command_t:=$command_t+""+$applicationPath_t+""
$command_t:=$command_t+"_CFURLStringType0
"
$command_t:=$command_t+"file-label"+$applicationName_t+""
$command_t:=$command_t+"file-type41
"
$command_t:=$command_t+"tile-typefile-tile
'"

LAUNCH EXTERNAL
PROCESS($command_t;$inputStream_t;$outputStream_t;$errorStream_t)
LAUNCH EXTERNAL PROCESS("killall -HUP Dock";$inputStream_t;$outputStream_t;$errorStream_t) ` relaunch the Dock