i need an applescript to open safari in full screen an to hide the toolbar on mavericks - safari

I need an applescript to open safari in full screen an to hide the toolbar on mavericks.
it sounds easy but it isnt!
i need to open safari then open google in full screen mode an then hide the toolbar.
it would be the equivilent to the below sample but instead for safari
tell application "Google Chrome"
open location "http://internet.ceo.wa.edu.au/Pages/default.aspx"
end tell
tell application "Google Chrome" to activate
tell application "System Events"
keystroke "f" using {command down, shift down}
end tell

Could be simple as this:
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 document at front
end if
tell application "System Events" to keystroke "f" using {command down, control down}
end tell
Not sure if you can make it with no toolbar at all.
Update 4/4
not sure what you can do with it but look into this program. If it works the way you want. Add a system events to use the drop downs to select the item.
The Barbarian Group has a freeware app called "Plainview", which seems to be just a wrapper around Webkit. It works as a "Fullscreen kiosk-style presentation content viewer", similar to what Chrome presentation mode does.
Anyways, it's a free download, so no risk in trying. Scroll almost to the bottom of this page:
http://barbariangroup.com
Direct download:
http://s3.amazonaws.com/plainviewapp/plainview_1.0.178.zip

Easy way:
set MyApps to {"Google Chrome", "Skype", "Finder"}
repeat with MyApp in MyApps
tell application MyApp
activate
delay 3
tell application "System Events" to tell process MyApp
set value of attribute "AXFullScreen" of window 1 to true
end tell
end tell
end repeat

Related

Open new tab in Safari on the right

I recently moved away from Mac OS Sierra (yes I know I'm late) to High Sierra and I was forced to update to Safari Version 13.1.2. Now I am profoundly annoyed by it opening new Tabs (⌘t) next to my active tab instead of all to the right as it used to.
I believe while in Safari, using the keyboard shortcut ⌥ ⌘ T Will open a new tab to the far right
tell application "Safari" to activate
tell application "System Events" to tell process "Safari"
keystroke "t" using {option down, command down}
end tell
Knowing now that there is a menu entry "New Tab at End", there is no need for an Apple script or QuickSilver or anything. Just open System Preferences > Keyboard > Shortcuts, and add a shortcut using the plus button like the following:
So here is how to work around it. Open "Script Editor" and paste this code:
tell application "Safari"
if windows is {} then
make new document
else
tell first window
set current tab to last tab
tell application "System Events" to tell process "Safari" to tell menu bar 1 to tell menu bar item "File" to tell menu 1 to click menu item "New Tab"
end tell
end if
end tell
Disclaimer: this code is highly inspired by the code from xhinter on Mac OS X Hints, all kudos to him.
Save the script as Tab in Safari on the right.scpt in your ~/Library/Scripts folder (important for Quicksilver to find it). To run it you will need to allow rights to the app in the accessibility settings, the system will prompt you, don't discard it.
Check if Quicksilver > Catalog includes your user scripts, and refresh it to make sure the newly created script is in the catalog. Go to Triggers > Custom Triggers, add one via the plus in the bottom and type tabin, it will bring up the script as result. Enter closes the window. Press the ℹ️ in the bottom. Under Settings, add the Shortcut ⌘t. Under Scope, select Enabled in selected applications, in the textfield enter "Safari" which will be parsed automatically. See here for a more detailed description of scripts in Quicksilver.
That's it. Have fun!

Cocoa application contains no menu bars, according to AppleScript

I am creating a mac app that needs to start dictation (OSX 10.8) by itself. Because there is no way to initiate dictation "directly" the best way to do this is through the menu bar "Edit"/"Start Dictation" because a user may have different keyboard shortcuts for it.
Here's the simple script my app calls (using an NSAppleScript object):
tell application "System Events"
tell application process "MyApp"
tell menu bar 1
tell menu bar item "Edit"
tell menu "Edit"
click menu item "Start Dictation"
end tell
end tell
end tell
end tell
end tell
Here are the results (NSLog'd the error from the AppleScript)
Error:-1719 System Events got an error:
Can’t get menu bar 1 of application process "MyApp". Invalid index.
I did a basic test to see what was going on
My App:
tell application "System Events"
tell application process "MyApp"
set x to menu bars
return x
end tell
end tell
result: <NSAppleEventDescriptor: [ ]>
Finder:
tell application "System Events"
tell application process "Finder"
set x to menu bars
return x
end tell
end tell
result: <NSAppleEventDescriptor: [ 'obj '{ 'form':'indx', 'want':'mbar', 'seld':1, 'from':'obj '{ 'form':'name', 'want':'pcap', 'seld':'utxt'("Finder"), 'from':null() } } ]>
So basically AppleScript is telling me my app has no menu bars? I run Accessibility Inspector and sure enough there is in fact a menu bar (plus I can see it...).
What's going wrong here?
I was after something similar, I wanted to activate a service from within Emacs which had otherwise overridden the global keyboard shortcut to the service - A different question which I will ask in another thread.
Running your examples above I did discover that I had to have added the application (Emacs and for testing Automator) to the Accessibility applications (System Preferences -> Security & Privacy -> Privacy -> Accessibility). Further information regarding that on select-a-menu-item-in-applescript-without-using-system-events-in-10-9-maverick and also AppleScript - uiscripting.
With that access in place I am able to see the menu items under services:
tell application "Emacs"
activate
end tell
tell application "System Events"
tell application process "Emacs"
tell menu bar 1
tell menu "Emacs"
tell menu item "Services"
tell menu "Services"
set x to menu items
click menu item "XXX"
return x
end tell
end tell
end tell
end tell
end tell
end tell
But the action is not activated!
Using the example above an error is returned that 'XXX' does not exist. Replacing the string with the correct string means no error occurs, but the action does not take place.
Have you tried activating your app with a short delay before running the system events stuff? You're also missing some other stuff. Here's how you would do it in Safari...
tell application "Safari" to activate
delay 1
tell application "System Events"
tell process "Safari"
tell menu bar item "Edit" of menu bar 1
click
delay 0.5
tell menu item "Speech" of menu 1
click
delay 0.5
click menu item "Start Speaking" of menu 1
end tell
end tell
end tell
end tell
A second point. If you are creating the application yourself then you do not need to do as you are suggesting. You state "Because there is no way to initiate dictation directly" but why do you say that? Every menu item is hooked up to a command, so in essence you can hook into that command if this is your own application. Just create a button or something in your interface and connect it to the same command that the menu item is connected to. For example I can see in Xcode that the "Start Speaking" menu item is connected to First Responder's startSpeaking command. As such you can create a button or some other item and connect it to startSpeaking of First Responder in Interface builder yourself.

Selenium - disable popup blocker

I have just spent hours stuck on Selenium with Safari before figuring out that I needed to disable popup blocker to allow a login popup that I have.
My question is, is there a way to disable the popup blocker when creating a node/webdriver with Selenium Grid 2, or when creating a RemoteWebDriver in code, or both?
Otherwise, I have to manually remember to change this setting by opening the browser myself. The aim is to have Selenium running across several machines so it would be great to be able to set this programatically.
Ok, here's the AppleScript that I ended up writing:
tell application "System Events" to tell process "Safari"
set frontmost to true
keystroke "," using {command down} -- open preferences
delay 1
tell window "Security"
tell group 1
tell group 1
click checkbox "Block pop-up windows"
end tell
end tell
key code 53 -- close preferences
end tell
end tell
if you save it as popup.as you can run it like this:
$ osascript popup.as
Keep in mind that this only works locally, not on a cloud service like Sauce Labs.

How to programmatically open Safari->preferences pane

I m working on safari plugin. I have added some Qt code in it. Now I want to open "safari->preferences" pane when user clicks on QPushButton on my Qt dialog.
If it is possible in Objective-C also, please tell me.
Finally I got it.
Here is my solution:
tell application "Safari" to activate
delay 4
tell application "System Events" to tell process "Safari"
keystroke "," using command down
tell window 1
click button "Extensions" of tool bar 1
activate "Extensions"
keystroke return
end tell
end tell
Using this AppleScript we can open Safari->Preferences programatically.
I dont know a direct api.
write an apple script and use ui scripting
to tell safari
1) to open
2) to select the menuitem preferences (maybe even send key stroke cmd+,)
some script like:
tell application "System Events"
tell process "Safari"
tell menu bar 1
tell menu bar item "Safari"
tell menu "Safari"
click menu item "Preferences..."
end tell
end tell
end tell
end tell

Application does not accept keystroke

I am trying to send keystrokes to the application VisualBoyAdvance using AppleScript, but I cannot get it to work.
My code, so far, is this:
tell application "VisualBoyAdvance"
activate
tell application "System Events"
keystroke "k"
end tell
end tell
When I tell VisualBoyAdvance directly, I get this error:
error "VisualBoyAdvance got an error: Can’t get keystroke \"k\"." number -1728 from keystroke "k"
I have tried telling VisualBoyAdvance directly, and I have also tried using key code 40, but I still cannot get it to work. Strangely enough, this does work:
tell application "VisualBoyAdvance"
activate
tell application "System Events"
keystroke "d" using {command down}
end tell
end tell
But that is a keyboard shortcut that shows up in the menu bar, so I guess it would be a bit different.
How can I use AppleScript to simulate a keypress and make the application respond to it? If I cannot use AppleScript for this, what else could I use?
I think you're almost there. Here's something I used for Safari; in this example, I send key code 48 (tab).
tell application "Safari"
activate
tell application "System Events" to tell process "Safari" to key code 48
end tell
AFAICS this ought to be largely independent of AppleScript support in the target process as you're asking System Events to simulate the key press via Universal Access.
For help with key codes, see this useful application: http://manytricks.com/keycodes/
It's the developer's choice to make an application fully Applescript aware. Menu items are Applescriptable from the Finder's point of view, but other UI options may or may not be. See UIElementInspector to examine that application for scriptable elements.
I can't garuntee anything as I don't have this app but here is some things to try
tell application "VisualBoyAdvance"
activate
tell application "System Events"
tell application process "VisualBoyAdvance"
try
keystroke "k"
on error
try
keystroke (ASCII character 75)
end try
end try
end tell
end tell
end tell