I have a working AppleScript for pinning a given app the dock:
set theAppPath to "/Applications/Adobe Acrobat Reader.app"
try
set theShellScript to "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & theAppPath & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
do shell script theShellScript
do shell script "killall -HUP Dock"
end try
but when I try to execute this inside a shell script using osascript it does nothing, here is the bash script:
#!/bin/bash
#!/usr/bin/env osascript
osascript <<EOD
set theAppPath to "/Applications/Adobe Acrobat Reader.app"
try
set theShellScript to "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & theAppPath & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
do shell script theShellScript
do shell script "killall -HUP Dock"
end try
EOD
exit 0
I've looked at a number of questions that explain this and my format looks correct, I was able to use osascript to create a shortcut in another part of the bash script, but am having issues embedding this AppleScript snippet into the bash script.
I am going to try using an external AppleScript (.scpt) and calling that with the bash, but would prefer not to have to.
This will probably be a separate question if needed, but ideally my bash script would use a variable $APP_PATH inside of the osascript instead of theAppPath.
PS. MacOS 15
I have tried running the AppleScript directly and it works, I have tried using osascript multiple ways to call the AppleScript commands and none work. I was successful with a different osascript implementation but can't figure out why this one doesn't work.
EDIT: Here is the snippet of working osascript with its embedded AppleScript commands, note that this one already uses variables declared outside of the osascript component and they work from my limited testing
osascript <<EOF
tell application "Finder"
make alias file to POSIX file "$APP_PATH/$APP_NAME" at POSIX file "$TARGET_FOLDER"
set name of result to "$SHORTCUT_NAME"
end tell
EOF
I have a working AppleScript for pinning a given app the dock:
set theAppPath to "/Applications/Adobe Acrobat Reader.app"
try
set theShellScript to "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & theAppPath & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
do shell script theShellScript
do shell script "killall -HUP Dock"
end try
but when I try to execute this inside a shell script using osascript it does nothing, here is the bash script:
#!/bin/bash
#!/usr/bin/env osascript
osascript <<EOD
set theAppPath to "/Applications/Adobe Acrobat Reader.app"
try
set theShellScript to "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & theAppPath & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
do shell script theShellScript
do shell script "killall -HUP Dock"
end try
EOD
exit 0
I've looked at a number of questions that explain this and my format looks correct, I was able to use osascript to create a shortcut in another part of the bash script, but am having issues embedding this AppleScript snippet into the bash script.
I am going to try using an external AppleScript (.scpt) and calling that with the bash, but would prefer not to have to.
This will probably be a separate question if needed, but ideally my bash script would use a variable $APP_PATH inside of the osascript instead of theAppPath.
PS. MacOS 15
I have tried running the AppleScript directly and it works, I have tried using osascript multiple ways to call the AppleScript commands and none work. I was successful with a different osascript implementation but can't figure out why this one doesn't work.
EDIT: Here is the snippet of working osascript with its embedded AppleScript commands, note that this one already uses variables declared outside of the osascript component and they work from my limited testing
osascript <<EOF
tell application "Finder"
make alias file to POSIX file "$APP_PATH/$APP_NAME" at POSIX file "$TARGET_FOLDER"
set name of result to "$SHORTCUT_NAME"
end tell
EOF
Share
Improve this question
edited Mar 21 at 0:50
Daniel T.S
asked Mar 20 at 23:17
Daniel T.SDaniel T.S
12 bronze badges
7
|
Show 2 more comments
1 Answer
Reset to default 0I found my issue and it was actually caused by running as sudo vs the user. When I was executing the AppleScript in the script editor it was running as my user account and editing the com.apple.dock.plist in my /User/.... folder. This has the intended behaviour of editing my dock. When I ran the same code, osascript or bash directly, as sudo it did not edit the com.apple.dock.plist in either my user directory or the system directory /Library/Preferences/.
I am now trying to use PlistBuddy to explicitly edit the file that I want, taking some time to learn today
I was successful with a different osascript
- what did that script look like? can you post a small, workable version in the question? – markp-fuso Commented Mar 20 at 23:46