I am trying to right click a button in the application "Pro Tools."
To do this I am trying to tell script editor/apple scripts to click the button using control down (which emulates a right click on a Mac). However, I keep getting an error message when I try to compile or run the code. I receive a syntax error message that says
Expected end of line, etc. but found number.
or
Expected end of line but found identifier.
that point to using.
tell application "System Events"
tell application process "Pro Tools"
click button "Record Enable" of group "Normal Transport Buttons" of group "Transport View Cluster" of window "Edit: BB MASTER TEMPLATE 2019 v1-14 copy" using key code 59
end tell
end tell
I have also tried using this code:
tell application "System Events"
(click button "record enable" of group "normal transport buttons" of group "transport view cluster" of window "Edit: BB MASTER TEMPLATE 2019 v1-14 copy" of application process "Pro Tools")
using key code 59
end tell
First things first, you'll make your life easier if you use nested tell blocks, like so:
tell application "System Events"
tell application process "Pro Tools"
tell window "Edit: BB MASTER TEMPLATE 2019 v1-14 copy"
tell group "Transport View Cluster"
tell group "Normal Transport Buttons"
click button "Record Enable"
end tell
end tell
end tell
end tell
end tell
Takes up more space, yes, but it's much easier to debug.
That being said, you might try using the perform command instead of click or key code. I mean, if there is a key equivalent for right-clicking the button that would be easiest, just use:
tell application "System Events"
tell application process "Pro Tools"
key code 59 using control down *-- or whatever*
end tell
end tell
but if not, try this first:
tell application "System Events"
tell application process "Pro Tools"
tell window "Edit: BB MASTER TEMPLATE 2019 v1-14 copy"
tell group "Transport View Cluster"
tell group "Normal Transport Buttons"
tell button "Record Enable"
log properties
log actions
end tell
end tell
end tell
end tell
end tell
end tell
and if the log shows an action for the button that seems on-point you can invoke it directly using:
tell group "Normal Transport Buttons"
tell button "Record Enable"
perform action 2 *-- or whatever*
end tell
end tell
It's hard to say more without more information...
Related
I wanted to find a way how to disable/enable hot corners via keyboard shortcut.
I found this apple script
property theSavedValues : {"Mission Control", "Desktop", "Dashboard", "Launchpad"} -- for example
tell application "System Preferences"
set current pane to pane id "com.apple.preference.expose"
tell application "System Events"
tell window "Mission Control" of process "System Preferences"
click button "Hot Corners…"
tell sheet 1
tell group 1
set theCurrentValues to value of pop up buttons
if theCurrentValues is {"-", "-", "-", "-"} then
repeat with i from 1 to 4
set thisValue to item i of theSavedValues
tell pop up button i
click
click menu item thisValue of menu 1
end tell
end repeat
else
copy theCurrentValues to theSavedValues
repeat with i from 1 to 4
tell pop up button i
click
click last menu item of menu 1
end tell
end repeat
end if
end tell
click button "OK"
end tell
end tell
end tell
quit
end tell
So I created an service in Automator with this apple script, attached it to keyboard shortcut, whenever I run this script in automator, it works but when i hit the shortcut, im getting "The action "Run AppleScript" encountered an error ".
Any ideas what can be done to fix this?
Thank you
Oh my god I feel so dumb, the only thing needed was to grant accessibility permission to app from which I'm using this service :).
You can do this by going to (Mac OS)Settings -> Security&Privacy -> Accessibility -> and finding the app from which you are running the service. (In my case it's Finder.)
I'm trying to write an AppleScript that will use the Save as Pictures... function of PowerPoint, but I'm wrestling with AppleScript. This is what I have:
set p to "file.pptx"
tell application "Microsoft PowerPoint"
launch
open p
delay 2
click menu item "Save as Pictures..." of menu bar item "File" of menu bar 1
end tell
and it isn't doing what I want. The specific error I get is:
script error: Expected end of line, etc. but found class name. (-2741)
And I don't know what to do. I've tried all sorts of things but I can't seem to get the right menu item to click. I'm using OSX 10.9 and PowerPoint 2011 (Version 14.3.2)
UPDATE:
This is now the script I have:
set p to "file.pptx"
tell application "Microsoft PowerPoint"
launch
open p
end tell
delay 2
tell application "System Events"
tell process "PowerPoint"
click menu item "Save as Pictures..." of menu 1 of menu bar item "File" of menu bar 1
end tell
end tell
And I'm getting an execution error: Microsoft PowerPoint got an error: Parameter error. (-50)
Gui automation is generally done through the "System Events" app.
Also you need to provide a full path to a file before trying to open it.
This is how you would begin your attack on PowerPoint correctly.
set p to POSIX file "/Users/drew/Desktop/file.pptx"
tell application "Microsoft PowerPoint"
launch
open p
end tell
delay 2
tell application "System Events"
tell process "PowerPoint"
click menu item "Save as Pictures..." of menu 1 of menu bar item "File" of menu bar 1
end tell
end tell
I am trying to create a script that will automatically close the frontmost window of Apple Pages.
on run {}
tell application "System Events"
if (window 1 of process "Pages" exists) then
try
tell application "Pages"
--display dialog "Hello World!" --TODO: remove, test code only.
--Keywords I have tried: file, document, window,
close window 1 saving no
end tell
--close window 1 of process "Pages" saving no
on error errMsg
display dialog "ERROR: " & errMsg
end try
end if
end tell
end run
Whenever I run this, it gives me the following error:
ERROR: Pages got an error: window 1 doesn’t understand the “close”
message.
I have looked at this article, and have used the following command:
sudo defaults write /Applications/Pages.app/Contents/Info NSAppleScriptEnabled -bool YES
However, it still fails to work. Any advice?
Details:
System Version: OS X 10.9.1 (13B42)
Kernel Version: Darwin 13.0.0
Pages: 5.0.1
If Pages isn't scriptable, you're kind of out of luck. If it were scriptable, you wouldn't need System Events to close a window; that kind of functionality is usually included in a scriptable app's dictionary.
System Events can help with apps that aren't scriptable, but you have to rely on the actual UI. But if that's the solution, you can't use tell application "Pages" for the inner block (like you have it); you have to use:
tell process "Pages"
If you go that route, now you have to use either the close button on window 1 or use the close menu command. Something like:
activate application "Pages"--note that this will probably be NECESSARY (if it's not frontmost, it prob won't work)
tell application "System Events"
tell process "Pages"
click menu item "Close" of menu "File" of menu bar item "File" of menu bar 1 of it
end tell
end tell
BUT then you have to come up with the problem of what happens if the window hasn't been saved (has been modified) -- which in a scriptable app uses the construction you were originally trying. When using System Events, you can do:
activate application "Pages"--note that this will probably be NECESSARY (if it's not frontmost, it prob won't work)
tell application "System Events"
tell process "Pages"
click menu item "Close" of menu "File" of menu bar item "File" of menu bar 1 of it
delay .5
keystroke "d" using command down
end tell
end tell
But then again how do you make the script smart enough to know if the window has been modified or not? Or maybe you use System Events to see if the window has been killed after the close command, and if it hasn't, it does the keystroke thing. This kind of thing can be done by doing something like:
activate application "Pages"
tell application "System Events"
tell process "Pages"
set frontMostWinName to name of window 1
click menu item "Close" of menu "File" of menu bar item "File" of menu bar 1 of it
tell me to delay 0.5
if exists window 1 then
if name of window 1 = frontMostWinName then keystroke "d" using command down
end if
end tell
end tell
I don't have Pages, but this works with another non-scriptable app, Bean (although I should mention that Bean uses tabs, and I had to move a tab to a window to get this to work*, and I don't know how Pages works in this regard).
[EDIT: *actually, this is not true; this works in Bean regardless of tabs/windows]
I am trying this simple GUI script to open a new window of Safari:
tell application "Safari"
activate
end tell
tell application "System Events"
tell process "Safari"
try
tell menu bar 1
tell menu bar item 3
click menu item 1
end tell
end tell
on error theError
display dialog ("An error occurred while performing requested action" & theError) buttons "OK" default button "OK"
end try
end tell
end tell
but it is giving this error message:
Expected end of line but found """
Can anyone suggest me where I may be wrong?
Thanks,
Miraaj
Wow, that was weird. Your script broke AppleScript Editor. After running your script and it not working... I tried to recompile the script and then the error you posted starting showing up. So somehow your code caused AppleScript editor to break and thus the error. I had to quit and relaunch AppleScript Editor to get it working again.
I used the application UI Browser and found the problem. Your reference to the menu item was wrong. There's an extra menu in there that we can't see... and you didn't reference that extra menu. This is the problem with gui scripting. And even if a gui script works it may break at some future date as an application is updated. As such avoid gui scripting if at all possible.
Anyway, here's what your code should look like...
tell application "Safari"
activate
end tell
tell application "System Events"
tell process "Safari"
try
tell menu bar 1
tell menu bar item 3
click menu item 1 of menu 1
end tell
end tell
on error theError
display dialog ("An error occurred while performing requested action " & theError) buttons "OK" default button "OK"
end try
end tell
end tell
EDIT:
As I mentioned in my comment below, if you can't find a native command from an application's dictionary, the next most reliable method is using keyboard shortcuts. Most menu items have them. For example, if I wanted to open a new tab in a window that menu item has the keyboard shortcut command-t. So we can use that like this. Note there is a native command to open a new tab without using keystrokes, I'm just showing this as an example.
tell application "Safari" to activate
tell application "System Events"
keystroke "t" using command down
end tell
end
Keyboard commands don't usually change between application updates whereas gui commands often do because programmers redesign their interface in updates... and when that happens gui scripting goes haywire. One of the gotcha's with both gui scripting and keystrokes is that sometimes the script goes too fast and these techniques can't keep up with the speed of the program, so they often error. When this happens you need to slow down the script using small delays to allow the interface to keep up with the script.
I don't have a Wi-Fi router, so when at home I need to turn my laptop into a Wi-Fi source so that both myself and my partner can access the internet.
However during the days I work at a coffee shop and require the use of their Wi-Fi.
I'm running Snow Leopard and I find it stupidly cumbersome to constantly be turning off and on, first Internet Sharing and then my Wi-Fi.
Any ideas for a quick 'n' dirty AppleScript solution?
You can use launchctl to programmatically start or stop the Internet Sharing service.
The following AppleScript will start Internet Sharing:
do shell script "/bin/launchctl load -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist" with administrator privileges
The following AppleScript will stop Internet Sharing:
do shell script "/bin/launchctl unload -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist" with administrator privileges
I'm using this AppleScript from Automator so that I can easily use it as a service and give it a keyboard shortcut.
Toggle Internet Sharing:
register_growl()
try
if isRunning("InternetSharing") then
do shell script "launchctl unload -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist" with administrator privileges
if isRunning("InternetSharing") then
error "Internet Connection Sharing was Not Disabled"
else
my growlnote("Success", "Internet Connection Sharing Disabled")
end if
else
do shell script "launchctl load -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist" with administrator privileges
if isRunning("InternetSharing") then
my growlnote("Success", "Internet Connection Sharing Enabled")
else
error "Internet Connection Sharing was Not Enabled"
end if
end if
on error errMsg
my growlnote("Error", errMsg)
end try
on isRunning(processName)
try
return 0 < length of (do shell script "ps ax | grep -v grep | grep " & processName)
on error
return false
end try
end isRunning
on register_growl()
try
tell application "GrowlHelperApp"
set the notificationsList to {"Success", "Warning", "Error"}
register as application "Toggle Internet Connection Sharing" all notifications notificationsList default notifications notificationsList icon of application "Sharing"
end tell
end try
end register_growl
on growlnote(growltype, str)
try
tell application "GrowlHelperApp"
notify with name growltype title growltype description str application name "Toggle Internet Connection Sharing"
end tell
end try
end growlnote
I am cross-posting this on the Apple stack exchange because the question was asked in both places.
Not sure if you are still looking for a solution but... here is an apple script to enable or disable internet sharing
tell application "System Preferences"
activate
reveal (pane id "com.apple.preferences.sharing")
end tell
tell application "System Events"
tell process "System Preferences"
try
click checkbox of row 11 of table 1 of scroll area of group 1 of window "Sharing"
if checkbox of row 11 of table 1 of scroll area of group 1 of window "Sharing" is equal to 1 then
repeat until sheet of window 1 exists
delay 0.5
end repeat
end if
if (sheet of window 1 exists) then
click button "Start" of sheet of window 1
end if
tell application "System Preferences" to quit
activate (display dialog "Internet Sharing preferences sucessfully flipped")
on error
activate
display dialog "something went wrong in automation but you are probably in the right menu..."
return false
end try
end tell
end tell
I also will post this on the apple stack exchange post.
Here's what I came up with for Mojave to toggle Internet Sharing using (mostly) accessibility — unfortunately none of the solutions involving using launchctl and/or editing com.apple.nat.plist worked for me.
open location "x-apple.systempreferences:com.apple.preferences.sharing?Internet"
tell application "System Events"
tell process "System Preferences"
repeat until window "Sharing" exists
delay 0.1
end repeat
tell window "Sharing"
set _row to group 1's scroll area 1's table 1's first row whose selected is true
set _wasSharing to _row's checkbox's value as number
if _wasSharing is 1 then
click _row's checkbox
set _wasSharing to _row's checkbox's value as number
repeat until _wasSharing is 0
delay 0.1
end repeat
end if
if _wasSharing is 0 then
click _row's checkbox
repeat until sheet 1 exists
delay 0.1
end repeat
click sheet 1's button "Start"
end if
end tell
end tell
end tell
tell application "System Preferences" to quit