I'm working on a shell script (#!/bin/sh) that uses defaults to read the com.apple.dock plist and gather the persistent-apps and persistent-others into arrays, however because some of the Applications have spaces in them, they are entered as separate entities in the array.
I've tried the following but with no luck...
Both of the above examples end up having spaces within Application names cutting the Application name into 2 array entities (i.e. "/Applications/Internet\ Explorer.app/" ends up as "/Applications/Internet\" and "Explorer.app/")
If I declare the array in the manner listed below, the spaces within applications names are honored. What I don't understand is that the output of the defaults command exactly matches what is manually declared.
Many thanks in advance!
I've tried the following but with no luck...
Code:
#!/bin/sh
# Arrays
currentPersistentApps=( `defaults read com.apple.dock persistent-apps | grep CFURLString | grep -v CFURLStringType | awk '{print $3, $4}' | sed 's/;//' | sed 's/[ \t]*$//' | sed '/\ /s/\ /\\\ /g' | tr '\n' ' '` )
# Output
echo "${currentPersistentApps[$1]}"
Code:
#!/bin/sh
# Variables
currentPA=`defaults read com.apple.dock persistent-apps | grep CFURLString | grep -v CFURLStringType | awk '{print $3, $4}' | sed 's/;//' | sed 's/[ \t]*$//' | sed '/\ /s/\ /\\\ /g' | tr '\n' ' '`
# Arrays
currentPersistentApps=( `echo "$currentPA"` )
# Output
echo "${currentPersistentApps[$1]}"
Both of the above examples end up having spaces within Application names cutting the Application name into 2 array entities (i.e. "/Applications/Internet\ Explorer.app/" ends up as "/Applications/Internet\" and "Explorer.app/")
If I declare the array in the manner listed below, the spaces within applications names are honored. What I don't understand is that the output of the defaults command exactly matches what is manually declared.
Code:
#!/bin/sh
# Arrays
currentPersistentApps=( "/Applications/Safari.app/" "/Applications/Mail.app/" "/Applications/Server/Server\ Admin.app/" "/Applications/Server/Workgroup\ Manager.app/" "/Applications/Server/Server\ Monitor.app/" "/Applications/iTunes.app/" "/Applications/Utilities/Terminal.app/" "/System/Library/CoreServices/Screen\ Sharing.app/" "/System/Library/CoreServices/Kerberos.app/" "/Applications/TextWrangler.app/" "/Applications/Adium.app/" "/Applications/Time\ Machine.app/" "/Applications/TextEdit.app/" )
# Output
echo "${currentPersistentApps[$1]}"
Many thanks in advance!