The reason you get the Syntax Error:
Expected “given”, “with”, “without”, other parameter name, etc. but found identifier.
defaults write com.apple.Dock orientation -string left;killall Dock
In Script Editor is because it is not AppleScript code!
It's a compound command to run in Terminal; however, it can be run in AppleScript by using the
do shell script command:
do shell script "defaults write com.apple.Dock orientation -string left;killall Dock"
That said though, I'd choose not to use it because the result of
killall Dock with unhide all hidden windows and can be very disruptive and messy.
An alternative is to use UI Scripting1 with System Preferences, and this can be done in a less disruptive manner then
killall Dock. 1Note that using UI Scripting may require accessibility privileges be granted.
The following example AppleScript code will toggle the position of the Dock between the Bottom and the Left side of the screen:
This was tested in Script Editor and works under macOS High Sierra.
if running of application "System Preferences" then
tell application "System Preferences" to quit
do shell script "killall 'System Preferences'"
repeat while running of application "System Preferences" is true
tell application "System Preferences" to ¬
reveal anchor "Main" of pane id "com.apple.preference.dock"
tell application "System Events" to tell application process "System Preferences"
repeat while not (exists (window "Dock"))
tell radio group 1 of window "Dock"
if value of radio button "Bottom" is 1 then
click radio button "Left"
else if value of radio button "Left" is 1 then
click radio button "Bottom"
quit application "System Preferences"
This example AppleScript code can be used in an Automator Service (Quick Action in macOS Mojave) using a Run AppleScript action, and assigned a keyboard shortcut in: System Preferences > Keyboard > Shortcuts > Services
Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g.
delay 0.5, with the value of the delay set appropriately.