Applescript for showing/hiding menu bar in full screen - applescript

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

Related

OSX tick menu bar checkbox

For my application MuteSpotifyAds I wan't to add a feature that automatically enables the Private Session mode.
To do so, I wan't to toggle the menu bar item Private Session in the menu Spotify of the OSX menu bar. I use the following applescript, which works:
Source: https://stackoverflow.com/a/16497564/6286431
tell application "System Events" to tell process "Spotify"
tell menu bar item 2 of menu bar 0
click
click menu item "Private Session" of menu 1
end tell
end tell
The problem is that I have to check if the checkbox is already ticked, because else I would disable the Private Session.
Is there a way to check if the menu checkbox is already ticked?
I've already tried this, but seems to only work for checkboxes in actual windows.
If you have a solution that does not use applescript, that's also good!
The information if the menu item is checked is in the attribute "AXMenuItemMarkChar" of the menu item
tell application "System Events" to tell process "Spotify"
tell menu bar item 2 of menu bar 1 -- AppleScript indexes are 1-based
tell menu item "Private Session" of menu 1
set isChecked to value of attribute "AXMenuItemMarkChar" is "✓"
if not isChecked then click it
end tell
end tell
end tell

Applescript Issue: "Not Allowed Assistive Access. (-1719)"

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.

AppleScript: Menu bar item click (but no AXDescription)

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.

Applescript to click on a specific icon in the Mac Menu Bar

Sometimes I use PdaNet to tether using my iPhone. The desktop client for OSX is not as rich as the one for windows. One of the chief differences is, that the OSX does not allow to automatically connect to iPhone as soon as the latter is plugged in.
Would you know of a way using Applescript to click on the PdaNet icon on the Menu Bar and then select and click the 'Connect' option on it ?
Here is what the 'PdaNetMac' application's menu bar icon looks like:
I have looked at the following questions but am an applescript newbie and am not sure how to search for PdaNet's icon on the menu bar:
Click menu item on Mac OSX Lion using AppleScript
Applescript: on clicking Menu Bar item via gui script
Accessing dock icon right-click menu items with AppleScript
I have confirmed that 'Enable Access for assistive devices' is enabled.
Based on the second question above, Here is my current attempt at doing this:
ignoring application responses
tell application "System Events" to tell process "PdaNet"
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 "PdaNet"
tell menu bar item 1 of menu bar 2
click menu item "Connect" of menu 1
end tell
end tell
Interestingly, the above script works for me fine when I change PdaNet to Flux.
Thanks!!
You were very close !!
I just downloaded the PdaNet application to test this, and the only edit I had to make to your script was change PdaNet to 'PdaNetMac` ( I was thinking that this is the Process Name and so used the process name displayed in Activity Monitor).
So this works for me:
ignoring application responses
tell application "System Events" to tell process "PdaNetMac"
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 "PdaNetMac"
tell menu bar item 1 of menu bar 2
click menu item "Connect" of menu 1
end tell
end tell
Hope this works for you too !!
(Very useful script, btw. Cheers !)

Applescript to Launch Chrome (with specifics)

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

Resources