The below code is throwing a error in AppleScript. I get error "iTerm got an error: Can’t make class «class Ptrm»." number -2710 from «class Ptrm» to class. Any suggestions what may be causing it? I am totally new to AppleScript but I was handed this possibly outdated script and need it to run so that it will spawn the below 5 operations in iTerm. All insight welcome! Thanks
tell application "iTerm"
set t to (make new «class Ptrm»)
tell t
activate «class Cssn»
«event ITRMLNCH» given «class Pssn»:"Default Session"
tell the last «class Pssn»
«event ITRMWrte» given «class iTxt»:"vagrant ssh"
«event ITRMWrte» given «class iTxt»:"cd /vagrant"
«event ITRMWrte» given «class iTxt»:"./devsettings.sh scripts/runserver.py"
delay 1
end tell
«event ITRMLNCH» given «class Pssn»:"Default Session"
tell the last «class Pssn»
«event ITRMWrte» given «class iTxt»:"vagrant ssh"
«event ITRMWrte» given «class iTxt»:"cd /vagrant"
«event ITRMWrte» given «class iTxt»:"./localsettings.sh ./scripts/runcelery.py worker -c 10 -A plug.tasks -Q celery,pushq"
delay 1
end tell
«event ITRMLNCH» given «class Pssn»:"Default Session"
tell the last «class Pssn»
«event ITRMWrte» given «class iTxt»:"vagrant ssh"
«event ITRMWrte» given «class iTxt»:"cd /vagrant/messaging"
«event ITRMWrte» given «class iTxt»:"python2.7 directoryServer.py"
delay 1
end tell
«event ITRMLNCH» given «class Pssn»:"Default Session"
tell the last «class Pssn»
«event ITRMWrte» given «class iTxt»:"vagrant ssh"
«event ITRMWrte» given «class iTxt»:"cd /vagrant/messaging"
«event ITRMWrte» given «class iTxt»:"python2.7 iHttp.py"
delay 1
end tell
«event ITRMLNCH» given «class Pssn»:"Default Session"
tell the last «class Pssn»
«event ITRMWrte» given «class iTxt»:"vagrant ssh"
«event ITRMWrte» given «class iTxt»:"cd /vagrant/messaging/src"
«event ITRMWrte» given «class iTxt»:"go run wsServer.go"
end tell
end tell
Have you tried resetting your computer's libraries?
Enter the following command into iTerm, then recompile your script and see if you are still getting this error.
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user
Related
I'm trying to create an an AppleScript to turn dictation on or off (not just make it start listening). My goal is to be able to disable dictation when I am on battery power. I am new to AppleScript and don't know how to do this. I need this to work on macOS Sierra.
I found my answer!
Here is my code if somebody wants it:
set quitting to 0
delay 1
repeat until quitting is 1
set PowerSource to (do shell script "pmset -g ps")
repeat until PowerSource does not contain "AC Power" or quitting is 1
set PowerSource to (do shell script "pmset -g ps")
end repeat
--START
tell application "System Events"
set ProcessList to name of every process
if "System Prefrences" is in ProcessList then
set ThePID to unix id of process "System Prefrences"
do shell script "kill -KILL " & ThePID
end if
end tell
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.keyboard"
end tell
tell application "System Events"
--Part 1:
tell process "System Preferences"
--Part 2:
delay 1
--Part 3:
tell application "System Events" to tell radio button "Dictation" of tab group 1 of window "Keyboard" of application process "System Preferences" of application "System Events" to if exists then click
tell application "System Events" to tell radio button "Off" of radio group 1 of tab group 1 of window "Keyboard" of application process "System Preferences" of application "System Events" to if exists then click
end tell
end tell
tell application "System Preferences" to quit
display notification "Hey siri is now off."
--END
repeat until PowerSource contains "AC Power" or quitting is 1
set PowerSource to (do shell script "pmset -g ps")
end repeat
--START
tell application "System Events"
set ProcessList to name of every process
if "System Prefrences" is in ProcessList then
set ThePID to unix id of process "System Prefrences"
do shell script "kill -KILL " & ThePID
end if
end tell
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.keyboard"
end tell
tell application "System Events"
--Part 1:
tell process "System Preferences"
--Part 2:
delay 1
--Part 3:
tell application "System Events" to tell radio button "Dictation" of tab group 1 of window "Keyboard" of application process "System Preferences" of application "System Events" to if exists then click
tell application "System Events" to tell radio button "On" of radio group 1 of tab group 1 of window "Keyboard" of application process "System Preferences" of application "System Events" to if exists then click
end tell
end tell
tell application "System Preferences" to quit
display notification "Hey siri is now on."
--END
end repeat
on quit
set quitting to 1
continue quit
end quit
Just open it in script editor and compile it into an application. Then launch the application. Hope this helps!
I have created aliases of applescripts to open multiple panes on iTerm. However, ever since the latest update the scripts stopped working. I keep getting this error:
syntax error: Expected end of line but found identifier. (-2741)
Here's the script:
newPaneDown() {
osascript -e "
tell application \"iTerm\"
make new terminal
tell the current terminal
activate current session
tell the last session
tell i term application \"System Events\" to key code 2 using {shift down, command down}
end tell
end tell
end tell"
}
newPaneLeft() {
osascript -e "
tell application \"iTerm\"
make new terminal
tell the current terminal
activate current session
tell the last session
tell i term application \"System Events\" to key code 2 using command down
end tell
end tell
end tell"
}
newPanes4x4() {
/usr/bin/env osascript <<-EOF
tell application "iTerm"
activate
launch session "Panes"
tell i term application "System Events" to keystroke "d" using command down
tell i term application "System Events" to keystroke "D" using command down
tell i term application "System Events" to keystroke "[" using command down
tell i term application "System Events" to keystroke "[" using command down
tell i term application "System Events" to keystroke "D" using command down
end tell
EOF
}
alias p2='newPaneLeft'
alias p3='newPaneDown && newPaneLeft'
alias p4='newPanes4x4'
Applescript is not backwards compatible since iTerm2 Version 3.
The new Applescript syntax is described here.
You should replace:
make new terminal
with
create window with default profile
I am using this AppleScript, that intends to activate QuickTime on OS X and automatically start recording audio.
When running the debug in Automator, the script seems to suddenly stop at the line "set lastLength to duration of x", and throws the error:
"AppleEvent handler failed".
What may be wrong with the script?
on run {input, parameters}
tell application "QuickTime Player"
activate
set x to new audio recording
start x
delay 1
set lastLength to duration of x
delay 1
set newLength to duration of x
try
repeat while lastLength is not equal to newLength
delay 1
set lastLength to newLength
set newLength to duration of x
end repeat
end try -- display alert name of document 1
set v to file of front document
set audioNotePath to "/Users/me/Dropbox/Inbox/- Voice Memos"
set thePath to POSIX path of audioNotePath
set dateVariable to do shell script "date '+%m.%d.%y'"
set timeVariable to do shell script "date +'%l.%M %p'"
tell x to activate
delay 1
tell application "System Events"
keystroke "w" using {command down}
delay 1
keystroke thePath
delay 1
keystroke return
delay 1
keystroke "AudioNote "
keystroke dateVariable
keystroke " "
keystroke timeVariable
delay 1
click pop up button "Format:" of group 1 of sheet 1 of window "Untitled" of application process "QuickTime Player" of application "System Events"
delay 1
key code 125
delay 1
keystroke return
delay 1
keystroke return
delay 1
open thePath
end tell
return input
end tell
end run
If you save the following as a stay open application in Script Editor, when you run the application, it will create a new audio recording and keep checking to see if you have manually stopped the recording. Once you do stop the recording, it will export the file, open it, and quit. If you really want it as an Automator action, just have the Automator action open the script application.
property savePath : "Desktop:" --update e.g.,: "Dropbox:Inbox:- Voice Memos:"
property defaultName : "AudioNote"
my start_recording()
on start_recording()
tell application "QuickTime Player"
activate
tell (new audio recording) to start
end tell
end start_recording
on export_recording()
set homeFolder to (path to home folder) as string
set dateTimeStamp to do shell script "date '+%m%d%y-%H%M%S'"
set audioNotePath to (homeFolder & savePath & defaultName & " " & dateTimeStamp & ".m4a")
tell application "QuickTime Player"
tell document 1
export in file audioNotePath using settings preset "Audio Only"
close saving no
end tell
end tell
return audioNotePath
end export_recording
on open_recording(audioNotePath)
tell application "QuickTime Player" --you could change this if you wanted to open the file in another app
repeat --keep trying until the file is exported and ready to be opened
try
delay 1
open file audioNotePath
exit repeat
end try
end repeat
end tell
end open_recording
on idle
try
tell application "QuickTime Player" to set documentName to name of document 1
if (documentName ≠ "Audio Recording") then
set audioNotePath to my export_recording()
my open_recording(audioNotePath)
quit
end if
end try
return 1
end idle
I have a modbook with a glitchy digitizer board. Until I can re-shield the cable that is causing the glitch I just want to turn the digitizer off. I found a page which taught me some code and I used it successfully last night. Upon reboot, however, it doesn't work anymore:
The script:
tell application "System Events"
set PTD to (unix id of process "PenTabletDriver") as text
do shell script "kill -STOP " & quoted form of (PTD)
end tell
The error message:
error "Can’t make «class idux» of «class prcs» \"PenTabletDriver\" of
application \"System Events\" into type text." number -1700 from
«class idux» of «class prcs» "PenTabletDriver" to text
Can I alter the code somehow to fix this problem?
PS:
I have read this post and, though it's similar, I do not understand how it could be applied to my problem.
Life is too short to mess with AppleScript. Try running the following command at the terminal prompt:
pkill -STOP PenTabletDriver
Also, check your login items to see if the driver is automatically started each time you log in. (More likely, though, is that it's configured to start at boot time via launchd.)
You can save the following script in a little applet:
set shellStr to "pkill -STOP PenTabletDriver"
do shell script shellStr
and run it whenever you need.
I think the other answers make a good point, a shell command is nice and quick. BUT, if you must have it in AppleScript, this seems to work for me....
tell application "System Events"
set PTD to (unix id of process "iTunes")
do shell script "kill -STOP " & quoted form of (PTD as text)
end tell
which results to
tell application "System Events"
get unix id of process "iTunes"
--> 37987
do shell script "kill -STOP '37987'"
--> error number -10004
end tell
tell current application
do shell script "kill -STOP '37987'"
--> ""
end tell
The Process ID is just a number so there is no need to quote it...
tell application "System Events"
set PTD to (unix id of process "iTunes")
do shell script "kill -STOP " & PTD
end tell
The above code is sufficient.
Why does this not work when I make it an app? Im trying to make this work but all it does is keystroke the commands in finder not terminal. It even works in the applescript editor just not as an app. Please help!
on run
tell application "Terminal" to quit
delay 5
tell application "Terminal" to activate
delay 3
tell application "System Events" to keystroke "n" using {command down}
delay 1
tell application "System Events" to keystroke "top" & return
delay 1
tell application "System Events" to keystroke "n" using {command down}
delay 1
tell application "System Events" to keystroke "open -a Bartender" & return
delay 1
tell application "System Events" to keystroke "open -a MobileMouseServer" & return
delay 1
tell application "System Events" to keystroke "open -a gfxCardStatus" & return
delay 1
tell application "System Events" to keystroke "open -a Caffeine" & return
delay 1
tell application "System Events" to keystroke "open -a Alfred" & return
delay 1
tell application "System Events" to keystroke "open -a smcFanControl" & return
delay 1
tell application "System Events" to keystroke "w" using {command down}
tell application "Finder" to display dialog "System startup successful." with title "T.R.A.V.I.S." with icon file "Macintosh HD:SCRIPTS:ICNS:travis.icns" giving up after 5
end run
Thanks
Consider this structure:
tell application "Terminal"
if not (exists window 1) then reopen
-- targets an existing window
do script "top" in window 1
-- open a new window
do script "open -a Bartender"
end tell