I wrote the following applescript to open a doc while also hiding some annoying persistent toolbars in my word processor app. It works great when I play directly from script editor. But when I turn it into an app, and try to play in Alfred (not Alfred 2), I get this:
Open "Bicycle" is not allowed assistive access. System Events got an error: Open "Bicycle" is not allowed assistive access. (-1719)
Oh, and I've tried more ordinary routes than "POSIX", but all bring the same result. Also, I'm running latest version of El Capitan.
tell application "Bean"
open POSIX file "/Users/MyDrive/Documents/Bicycle.rtf"
end tell
activate application "Bean"
delay 0.3
tell application "System Events"
tell process "Bean"
click menu item "Hide Ruler" of menu 1 of menu bar item "View" of menu bar 1
click menu item "Hide Status Bar" of menu 1 of menu bar item "View" of menu bar 1
click menu item "Hide Toolbar" of menu 1 of menu bar item "View" of menu bar 1
end tell
end tell
Since
"Bicycle" is not allowed assistive access
allow it by open
System Preferences > Security & Privacy > Privacy > Accessibility
and check the appropriate checkbox.
Related
I am trying to write an applescript to hide the menubar in fullscreen when i watch movies. Otherwise i want it always turned on. I have come so far as to reveal the tab "Dock & Menu Bar" but i don't know how to click the right checkbox.
The following code is what i have come up with but as stated it isn't much.
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.dock"
end tell
For reference: I want to click the checkbox "Automaticly hide and show the menu bar in full screen"
When any application is in "Full Screen Mode", the menu bar is automatically hidden. However, if the app is "Zoomed", this following AppleScript code will toggle the autohide menu bar to on or off.
tell application "System Events"
if not autohide menu bar of dock preferences then
set autohide menu bar of dock preferences to true
else
set autohide menu bar of dock preferences to false
end if
end tell
I would like to control an application (Shady.app) with an AppleScript command. Unfortunately it doesn't have the standard menubar items such as File, Edit, View, etc.
My goal is to somehow issue a command to the app through AppleScript such that it will toggle the "Turn Shady On" & "Turn Shady Off" command:
NOTE: "Turn Shady On" is the OFF state and it turns to "Turn Shady Off" when Shady is in the ON state.
How can you create a script that toggles this both directions based on it's current state in AppleScript? Or is there a better way than AppleScript to control this programmatically?
This AppleScript will "Turn Shady Off"
tell application "System Events"
try
click menu item "Turn Shady Off" of menu 1 of menu bar item "Shade" of menu bar 1 of application process "Shady"
click menu bar item 1 of menu bar 2 of application process "Shady"
end try
end tell
This AppleScript will "Turn Shady On"
tell application "System Events"
try
click menu item "Turn Shady On" of menu 1 of menu bar item "Shade" of menu bar 1 of application process "Shady"
click menu bar item 1 of menu bar 2 of application process "Shady"
end try
end tell
Assuming it's being run in the status bar.
This will toggle on and off
on toggle()
tell application "System Events"
try
click menu item "Turn Shady On" of menu 1 of menu bar item "Shade" of menu bar 1 of application process "Shady"
end try
try
click menu item "Turn Shady off" of menu 1 of menu bar item "Shade" of menu bar 1 of application process "Shady"
end try
click menu bar item 1 of menu bar 2 of application process "Shady"
end tell
end toggle
toggle()
Save it as an application In ScriptEditor or as a service in Automator or whatever you choose. No need for FastScripts.
The standard way to send a command via short-cut is by:
System Preferences > Keyboard > Shortcuts > App Shortcuts
Click the + and select Shady, then you'll be able to define the short-cut you want to use. Keep in mind you'll need to use ⌘ + Tab to switch to Shady first, then use the short-cut.
If you use an application like FastScripts then you can create a global short-cut without having to switch to the application first which is sometimes better if the app doesn't have focus.
You can do something like this via Keyboard Maestro. Here's an image demonstrating what you want in action:
For the record, I also thought this was so awesome that I also included a way to create a darken/lighten global shortcut:
You've also gotta have "Show Dock Icon" turned on in system preferences for this to work!
See this post on the forums for more info. I'll go ahead and paste it here as well for convenience's sake and to circumvent link rot:
sonicly:
I have an application that runs only as a menubar app. It has a simple command that is essentially "Turn App On"/"Turn App Off". Is there a way to make Keyboard Maestro set up a global hotkey to initiate the command in this app?
I just ran across this topic which addresses your issue: osx - How to send a menubar app (with no menubar menu items) a command in AppleScript? - Stack Overflow
I don't know if you are the OP or not, and I have NOT tested the suggested solution. But maybe it will at least get you started.
sonicly:
So I can enable it to show up on the Dock and with that I was able to set keyboard shortcuts that work... But I have to get focus on the app first (i.e., cmd-tab). That's a hassle and I'd rather just issue something like command-option-shift-space to turn it on and then to toggle it back off again. That seems doable with KM, but I'm not sure how to make the Maestro do that per se
This is very easy in KM, just use the
Activate a Specific Application action (KM Wiki)
Type a Keystroke action (KM Wiki) to issue the shortcut key.
Another option is to use the Select or Show a Menu Item action (KM Wiki), but I'm not sure if it will work in this situation.
I'd like to AppleScript to click a menu bar icon (not a system process) and then click on one of the menu items. I'm using OS X 10.10.
I've read that I can use the Accessibility Inspector to find the AXDescription of the item, however, I can't find it anywhere in the inspector (in fact none of the items I inspected seemed to have this property).
I also tried the method described here but get an error on line 10:
ignoring application responses
tell application "System Events" to tell process "Webcam Settings"
click menu bar item 1 of menu bar 2
end tell
end ignoring
do shell script "killall System\\ Events"
delay 0.1
tell application "System Events" to tell process "Webcam Settings"
tell menu bar item 1 of menu bar 2
click menu item "Show Webcam Settings Panel" of menu 1
end tell
end tell
System Events got an error: Can’t get menu 1 of menu bar item 1 of menu bar 2 of process "Webcam Settings". Invalid index.
There are some menu bar apps which you can click and show menu with applescript regardless of if they appear in dock.
But I am afraid you can’t access the menubar of “Webcam Settings” with applescript.
Because there isn’t key named “isAccessbiliyFocused” in the attributes.
Menu bar apps you can show their menu with applescript have that key and its value is “Yes”.
I am not quite sure about my answer but as far as I investigate this issue, my answer is probably right.
I'm really struggling with creating some method of launching a browser window (chrome) on osx with specifics such as window size, no tabs etc. Traditionally I've used vb script through windows with IE which is a pretty simple exercise but I'll be the first to admit, when it comes to macs I struggle greatly.
So here is my wish list.
I need to be able to open a window (ideally in chrome, but any other browser except safari), that has no status bar, no address bar with a given URL, and a specific window size. I did manage something in safari using do javaScript, and attempted the same with chrome using execute javascript and 'window.open' but this failed continually...
Help!
I didn't find any way to hide the toolbar in Chrome, but try something like these scripts:
tell application "Google Chrome"
open location "http://example.com"
tell window 1 to enter presentation mode
end tell
tell application "Google Chrome"
tell (make new window)
set URL of active tab to "http://example.com"
set bounds to {0, 22, 1200, 900}
end tell
activate
end tell
tell application "Safari"
make new document with properties {URL:"http://example.com"}
tell window 1
set bounds to {0, 22, 1200, 900}
end tell
activate
end tell
tell application "System Events" to tell process "Safari"
tell menu "View" of menu bar 1
if exists menu item "Hide Toolbar" then click menu item "Hide Toolbar"
if exists menu item "Hide Status Bar" then click menu item "Hide Status Bar"
if exists menu item "Hide Tab Bar" then click menu item "Hide Tab Bar"
if exists menu item "Hide Bookmarks Bar" then click menu item "Hide Bookmarks Bar"
end tell
end tell
Using AppleScript I would like to automate the creation of a new user accounts on multiple machines. I'm trying to use UI Scripting and cannot seem to be able to do a click command on the "Add Account" (+) button in the iChat Accounts Preference window. I've tried to use the Accessibility Inspector.app to infer the name of the button but I still cannot seem to access it via AppleScript.
According to Accessibility Inspector.app the button has the following attributes:
AXRole: AXButton
AXRoleDescription: button
AXHelp: <nil>
AXEnabled: YES
AXFocused (W): NO
AXParent: <AXGroup>
AXWindow: <AXWindow:AXStandardWindow>
AXTopLevelUIElement: <AXWindow:AXStandardWindow>
AXPosition: x=225.00 y=462.00
AXSize: w=23.00 h=22.00
AXTitle: <empty string>
AXIdentifier: _NS:27
AXDescription: Add Account
Here is a sample starter AppleScript that will get you to the Accounts Preference window:
tell application "iChat"
activate
tell application "System Events"
tell process "iChat"
tell menu bar 1
click menu item "Preferences…" of menu "iChat"
end tell
click button "Accounts" of tool bar 1 of window 1
click button "Add Account" of window "Accounts"
end tell
end tell
end tell
Please note that line 9 is what I'm trying to get working. Below you will find a link to a screenshot of the iChat Accounts Preference window with an arrow pointing to the button that I'm trying to access. Also note that I know that I can just use "keystroke tab" to get to the (+) button, but this will not always work as the number of times you must press tab changes depending on the type of accounts that you already created in iChat.
iChat Account Preferences Window
Not every Ui object has a title, so in those cases you can just use the item number - note that you need to include the entire hierarchy shown in the Inspector window.
tell application "iChat"
activate
tell application "System Events"
tell process "iChat"
tell menu bar 1 to click menu item "Preferences…" of menu "iChat"
delay 0.5
tell window 1
click button "Accounts" of tool bar 1
delay 0.5
click button 1 of group 1 of group 1
end tell
end tell
end tell
end tell