OSX Mountain Lion & Applescript - Finder 'steals' focus - applescript

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!

Related

Control Finder's window "tab-bar" visibility with Applescript?

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

Apple script to activate a window that pops up within Firefox accurately

I have written this piece of code on my MAC OS X 10.10.5 to automate keystrokes on a window that pops up within Firefox.
It does not work reliably and, in many cases, performs the keystrokes on the window in the background. I have tried increasing the delay but it does not seem to be related to timing. The problem, instead, seems to be that the wrong Firefox window is activated.
This is my code. Any ideas on how I can fix it to work reliably.
set myBrowser to "/Applications/Firefox.app"
tell application myBrowser
activate window 2
end tell
tell application "System Events"
keystroke tab
delay 2
keystroke enter
end tell
If Firefox opens up a pop-up window, I believe that window now becomes window 1. The system events will be sent to that front pop-up window. Try using this code
activate application "Firefox"
tell application "System Events"
delay 2
key code 48
delay 1
key code 36
end tell

Applescript to open an application in full-screen mode?

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

How can I trigger keyboard commands via AppleScript in a Flash-generated upload prompt?

I'm trying to submit upload a photo to a website via AppleScript.
The basic experience is:
Load Site [done]
Click "Upload" [done - triggers Choose File prompt in what looks like the Finder, but still says Safari in top left]
Type file path in prompt and submit using:
tell application "System Events"
keystroke "g" using {shift down, command down}
keystroke "/Users/myUser/Pictures/myPic.jpg"
key code 36
end tell
But instead the AppleScript just stops moving once the prompt appears, and waits for human interaction. How can I use AppleScript to upload an image in a prompt like this?
Demo of the web side of things: http://www.uploadify.com/demos/
Assume I can click the "Select Files" button in this demo via AppleScript. How can I continue to use AppleScript to enter the file path and submit?
You need delays in the code like #mklement0 said
and to also make sure safari is activated
tell application "safari"
activate
tell application "System Events"
keystroke "g" using {shift down, command down}
delay 1.6
keystroke "/Users/myUser/Pictures/myPic.jpg"
delay 1.6
key code 36
end tell
end tell

How to open Firefox in Full Screen mode?

I need to open Firefox on a Mac running Lion in Full Screen mode to act as a kiosk.
I was using the R-Kiosk 0.9.0 Firefox Add-on; but, it conflicts with a print javascript I am also running, so I can't use it.
Anyone know a way to accomplish this? either with an add-on or, perhaps, with AppleScript? Could an AppleScript be triggered to run when Firefox is opened?
This should do it:
activate application "Firefox"
delay 2
tell application "System Events"
tell process "Firefox"
click menu item "Full Screen" of menu 1 of menu bar item "View" of menu bar 1
end tell
end tell
or maybe a keystroke:
activate application "Firefox"
delay 2
tell application "System Events"
keystroke "f" using {command down, shift down}
end tell
Starting from version 71, you can open Firefox with the --kiosk parameter to open it in full screen.
Ex:
c:\"Program Files (x86)\Mozilla Firefox\firefox.exe" --kiosk

Resources