Is there a way in Applescript to control visibility of a Finder's window "tab-bar" (don't know the english name)?
I know Applescript can get/set statusbar and toolbar visibility, but found nothing of this "tab-bar", the one that let you have multiple tabbed windows).
This AppleScript code works for me using the latest version of macOS Mojave.
tell application "Finder"
activate
delay 0.1
if not (exists of window 1) then reveal desktop
delay 0.1
tell its window 1
activate
repeat until visible
delay 0.5
end repeat
delay 1
tell application "System Events" to key code 17 using {command down, shift down}
end tell
end tell
SIDE-NOTE: This code will not work if your Finder window 1(Frontmost Finder Window) is open with more than one tab already opened
Related
(I have asked this on Reddit got couple of suggestions but they are not ideal so I though I might try my luck here)
I want to have either Menu bar toggle (like BT or WIFI) or keyboard shortcut [⌘+F12] that toggles Remote_Login on/off in the background without opening the system preferences window...
Remote Login
Idea of perfect solution
I am currently using or Keysmith macro that:
opens system preferences > sharing > clicks coordinates of the box next to Remote Login > quit
(but its not ideal because it shows the window while doing it)
Maybe there would be a way to modify this code (1st solution) into toggling Remote Login
or maybe someone has other suggestions...
With the help of a kind Redditor I modified the earlier code into this:
if running of application "System Preferences" then
try
tell application "System Preferences" to quit
on error
do shell script "killall 'System Preferences'"
end try
delay 0.1
end if
repeat while running of application "System Preferences" is true
delay 0.1
end repeat
tell application "System Preferences" to ¬
set the current pane to pane id ¬
"com.apple.preferences.sharing"
tell application "System Events"
tell front window of application process "System Preferences"
repeat until (exists checkbox 1 of row 5 of table 1 of scroll area 1 of group 1)
delay 0.01
end repeat
click checkbox 1 of row 5 of table 1 of scroll area 1 of group 1
delay 0.1
end tell
end tell
tell application "System Preferences" to quit
If I have two safari windows open, just one tab in each, how do I get applescript to switch to either of the windows at will? Or in other words, toggle between them.
I tried, activate window 1 (or, the first window), and activate window 2 (or the second window), only ever activates the first window.
I tried open window 1 etc, open doesn't exist.
I tried using the system events, click menu bar 1 option, thinking maybe menu bar 2 was for window 2, didn't work.
I tried making do javascript on a specific tab show that page, couldn't get that to work.
Ultimately I did figure out I could use a keyboard shortcut, but I wanted to see if there was a more 'vanilla' applescript way.
If the windows are not full screen (in different spaces) just change the index of the window
tell application "Safari"
set index of window 2 to 1
end tell
If the windows are in different spaces you have to switch the spaces by executing the keystrokes with System Events. The default values on the US keyboard are ⌃←
tell application "System Events"
key code 123 using (control down)
end tell
and ⌃→
tell application "System Events"
key code 124 using (control down)
end tell
When I do just this
tell application "Safari"
set index of window 2 to 1
end tell
The new window that shows up is frozen. I fixed this by doing this
tell application "Safari"
set theWindows to windows
set win2 to item 2 of theWindows
tell win2
set visible to false
set visible to true
set index to 1
end tell
activate
end tell
I'm trying to program Alfred to open my Terminal, Sublime Text, and Chrome with a workflow.
I would like for my terminal to open normally as a window, but I've been trying to get Chrome and Sublime to open full screen.
I was able to get Chrome to open up in full screen mode with:
on alfred_script(q)
tell application "Google Chrome"
tell window 1 to enter presentation mode
end tell
end alfred_script
However, this did not translate to work with my Sublime Text.
What am I missing here?
Another way to do this assuming you have not changed the default keyboard shortcut for "Enter Full Screen" is simply to have System Events invoke that shortcut (⌃⌘F). As with the other approach I've seen to doing this (changing the value of AXFullScreen—see mklement0's answer here for a thorough discussion of this method), this requires making the relevant window active.
For instance, to toggle the full-screen state of the frontmost window in Safari, run:
tell application "Safari" to activate
tell application "System Events"
keystroke "f" using {command down, control down}
end tell
As found here (i need an applescript to open safari in full screen an to hide the toolbar on mavericks). The make new document line prevents the can't get window 1 error by opening a new tab if one has not previously been opened.
tell application "Safari"
make new document
activate
delay 3
tell application "System Events" to tell process "Safari"
set value of attribute "AXFullScreen" of window 1 to true
end tell
end tell
I am pretty new to programming, especially with AppleScript. I wrote a simple script for Valentine's Day to play a song from iTunes and then open a flash animation file in Safari. When I run the script in ScriptEditor, everything works as desired, but when I export as a standalone application, it fails at the command to enable full-screen mode. I am assuming it is an issue with System Events. To be clear, the application functions to the end, but at the keystroke command I hear an alert sound and the window remains as-is.
I am running Yosemite, and am fully updated.
Ideally, I would like to open the file in Google Chrome to utilize Presentation Mode, but I can't even get Chrome to open the file.
Thanks for any advice! Here is the code:
tell application "Finder"
set visible of every process whose visible is true and name is not "Finder" to false
close every window
end tell
set volume output volume 75
tell application "iTunes"
set currentVolume to sound volume
if player state is playing then
stop
back track
end if
play track "The Promise"
set player position to 6
end tell
delay 4
tell application "Safari"
activate
if (count of windows) is 0 then -- Remove "if" statement if you don't want to make a new window if there is none
make new window at front
end if
open (POSIX path of (path to home folder)) & "/Desktop/beMine/beMine.swf"
tell application "System Events"
tell process "Safari" to keystroke "f" using {command down, control down}
end tell
end tell
I agree with Jerry Stratton's comment that it could be an accessibility issue. However it also could be that you are issuing the keystroke command before Safari is ready to accept it. If it's opening a file then it could be busy and miss the keystroke command.
Also, I would move the system events code outside the Safari code and also just tell system events, rather than the Safari process, to perform the keystroke command. Try this as the Safari and System Events parts.
NOTE: I can't get Chrome to open a file either.
tell application "Safari"
activate
if (count of windows) is 0 then -- Remove "if" statement if you don't want to make a new window if there is none
make new window at front
end if
open (POSIX path of (path to home folder)) & "/Desktop/beMine/beMine.swf"
end tell
tell application "Safari" to activate
delay 1
tell application "System Events"
keystroke "f" using {command down, control down}
end tell
Most likely you’ll need to allow your standalone application to use System Events. At some point you needed to do that for Script Editor; you’ll need to do the same for your standalone app.
You’ll find the option in System Preferences under Security & Privacy, then Privacy, and then Accessibility. There’ll be a list of apps, and your app is probably listed there without a check for “Allow the apps below to control your computer.”
You may need to use the “+” button to add your app to the list.
I have verified that I can use this simple script to make Safari full-screen; it will work if the app is given permission under Accessibility, and it will silently fail if not.
tell application "Safari"
activate
end tell
tell application "System Events"
tell process "Safari" to keystroke "f" using {command down, control down}
end tell
This is Yosemite, Mac OS X 10.10; it may be different in other versions of Mac OS X.
I've searched high and low to find a solution for this but have come up trumps.
I have a simple Applescript to wait for a minute, before opening a browser in fullscreen mode. (Allowing MAMP to startup as well).
The problem I face is, "Finder" has focus, and when the Applescript goes to execute the fullscreen command 'keystroke f {command down, shift down} it opens the "All Files" dialog, rather than the desired, Browser focused, enter fullscreen.
Does anyone know how to get around this please?
Couldn't you also activate the target application before entering full screen?
delay 10
tell application "Safari"
activate
reopen
end
tell application "System Events" to tell window 1 of process "Safari"
perform action "AXPress" of (button 1 where subrole is "AXFullScreenButton")
end tell
keystroke tab using {command down}
delay 1
keystroke "f" using {command down, shift down}
This works in my instance as the Finder had focus, and the next open application was my browser, which was the one I wanted to have focus. So if I were to do this manually I would hold COMMAND and press TAB once, to get the focus of the 'next app'
I'm not sure that the delay is required, but I added a 1 second delay just to make sure that the browser had focus, and then I execute the keystrokes to invoke fullscreen mode!