I have tried to use set "visible" = false
and
tell application "Google Chrome"
set miniaturized of every window to true
end tell
Both methods work for Safari, but not for Chrome. How do I fix this?
You're using the correct AppleScript terms for Safari, but the terms are different for Chrome (minimized instead of miniaturized). You can inspect the AppleScript dictionary using your script editor to find the correct terms. Or you can, as I did, do
tell application "Google Chrome"
properties of window 1
end tell
to return the various properties of a window to give you clues. An example of working AppleScript code is below.
tell application "Google Chrome"
set minimized of every window to true
end tell
Related
I've run into a bit of roadblock and I could use a suggestion. Part of a script that I'm writing, I'm targeting an extension in the Chrome brower to take a full page screen shot of a site. I've been able to identify the element using the Accessibility inspector but I can't figure out how to click on the element. I've tried several variants of the attached code without much luck.
tell application "System Events"
tell process "Google Chrome"
tell group "Extensions" of group "BBC - Homepage - Google Chrome" of window "BBC - Homepage - Google Chrome"
click (first button where its accessibility description = "Full Page Screen Capture")
end tell
end tell
end tell
as well as
tell application "System Events"
delay 1
tell process "Google Chrome"
click UI element "Full Page Screen Capture" of group "Extensions" of group "BBC - Homepage - Google Chrome" of window "BBC - Homepage - Google Chrome"
end tell
end tell
Also: I can target other elements in the Extensions group (i.e. Window Resizer) but this one does not want to cooperate.
Any suggestion would be welcome. Thank you in advance.
Firstly, we open a blank new tab in Google Chrome. Less UI elements is good for analysis. then we run the code(XXX) below:
tell application "Google Chrome"
activate
delay 0.3
end tell
tell application "System Events"
tell front window of (first application process whose frontmost is true)
set uiElems to entire contents
end tell
end tell
Search "screen" in the text output, we see line like this:
button "Full Page Screen Capture" of group "Extensions" of group "New
Tab - Google Chrome" of window "New Tab - Google Chrome" of
application process "Google Chrome",
So we know
the button is in group(Extensions),
the group(Ext...) is in group(New Tab...),
the group(New tab...)is in window...
So we test the code below:
tell application "Google Chrome"
activate
delay 0.3
end tell
tell application "System Events"
tell process "Google Chrome"
tell window "New Tab - Google Chrome"
tell group "New Tab - Google Chrome"
tell group "Extensions"
tell button "Full Page Screen Capture"
click
--perform action "AXPress"
end tell
end tell
end tell
end tell
end tell
end tell
It works. But we see the name of the active tab "New Tab - Google Chrome" is in the code, so if we go to another tab, the code doesn't work.
So we need to know how to get the name of the active tab of the front window. I did a lot of test. Finally I find answer on this page.
osascript -e 'tell app "google chrome" to get the title of the active tab of window 1'
Then I put it in my AppleScript, test the code below:
tell application "Google Chrome"
activate
delay 0.3
end tell
tell application "System Events"
tell process "Google Chrome"
set theTitle to do shell script "osascript -e 'tell app \"google chrome\" to get the title of the active tab of window 1'" as text
set theTitle to theTitle & " - Google Chrome"
--note the example title is "New Tab - Google Chrome". Don't forget to attach " - Google Chrome"
tell window theTitle
tell group theTitle
tell group "Extensions"
tell button "Full Page Screen Capture"
--click
perform action "AXPress"
end tell
end tell
end tell
end tell
end tell
end tell
Most of the time, this version of code works, BUT sometimes it doesn't work. I run code(XXX) at this tab, interesting, the button name changed from "Full Page Screen Capture" to "Full Page Screen Capture
Has access to this site" Note it inserts a "\r" after the word "Capture". So we know the Title of Window may change, and the button name may change. So I try to make a handler. Test the code below:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "Google Chrome"
activate
delay 0.3
end tell
try
set buttonName to "Full Page Screen Capture"
fullPageScreenshot(buttonName)
on error
set buttonName to "Full Page Screen Capture
Has access to this site"
--note here is a "\r"
fullPageScreenshot(buttonName)
end try
on fullPageScreenshot(buttonName)
tell application "System Events"
tell process "Google Chrome"
set theTitle to do shell script "osascript -e 'tell app \"google chrome\" to get the title of the active tab of window 1'" as text
delay 0.2
set theTitle to theTitle & " - Google Chrome"
--note the example title is "New Tab - Google Chrome". Don't forget to attach " - Google Chrome"
tell window theTitle
tell group theTitle
tell group "Extensions"
tell button buttonName
--click
perform action "AXPress"
end tell
end tell
end tell
end tell
end tell
end tell
end fullPageScreenshot
Now this version code, I test it more than 20 times, it always work. I do not use this extension too frequently. My Google Chrome version is Version 80.0.3987.149 (Official Build) (64-bit); and MacOS 10.12.6. Please let me know if this code works on your machine.
Is there away to capture a screenshot of the full page, including what is below the fold, in a Chrome Extension?
The captureVisibleTab seems to be limited to what is displayed within the visible area.
The standard approach seems to be to scroll around the page and capture screenshots at each part and then stick them all together. The official google screen capture plugin does this, but I found it to be buggy (at least on Mac OSX), so I wrote my own full page screen capture extension.
Source code here (relevant code in page.js and popup.js).
On Macs, while not a Chrome extension, you can use the following AppleScript to automate the process found here:
https://zapier.com/blog/full-page-screenshots-in-chrome/
tell application "Google Chrome" to activate
tell application "System Events"
keystroke "i" using {option down, command down}
delay 0.3
keystroke "p" using {shift down, command down}
delay 0.3
keystroke "Full"
delay 0.5
key code 76
end tell
Open ScriptEditor and paste that script in. Save it as a file wherever you need it locally. When you run it by pressing play in ScriptEditor, it will automatically save a full screenshot of the active tab to your Downloads folder.
Chrome 59 adds a new feature in DevTools called Capture full-size screenshot. But I don't know whether this API can be called by extensions.
You're limited to capturing the visible page via captureVisibleTab unless you use Flash or NPAPI.
I'm trying to get the URL from Safari, close the tab and open it in Chrome ( TUAW Post ) But I keep getting the error:
error "Safari got an error: Can’t get current tab." number -1728 from current tab
From the code line:
set theURL to URL of current tab of window 1
Any suggestions?
All the code:
property theURL : ""
tell application "Safari"
set t set theURL to URL of current tab of window 1
close current tab
end tell
tell application "Google Chrome"
set URL of active tab of window 1 to theURL
activate
end tell
It works for me...
tell application "Safari"
set theURL to URL of current tab of window 1
end tell
You have to show more code because the error is caused by something else. Let me ask you this, do you have the tell application Safari statement inside of another tell block? Maybe it's inside the tell google chrome block of code? If so remove it.
Thanks a lot guys! Here is the final code.
property theURL : ""
tell application "Safari"
set theURL to URL of current tab of window 1
end tell
tell application "Google Chrome"
tell window 1
make new tab with properties {URL:theURL}
end tell
activate
end tell
I am trying to using Google Chrome to automate my testing of a mobile app developed in JavaScript for iPhone, and since it is Webkit based only Safari and Google Chrome can render the content, so I have no other option then to use watir-webdriver.
I have done a lot of research in trying to find a solution to automate on Google Chrome and the closest I could get is with Watir-WebDriver.
I have the following code:
require "rubygems"
require "watir-webdriver"
browser = Watir::Browser.new(:chrome)
website = "http://xxx.yyy.zzz"
browser.goto(website)
browser.link(:xpath,"/html/body/div/ul/li/a").click #step1
browser.link(:xpath,"/html/body/div/div[2]/div/ul/li//*[#id=btn_WEBURL]").click #step2
As soon as the #step1 is executed, the content is opened in a new browser window, which results in:
C:/Program Files/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.2/lib/watir-
webdriver/elements/element.rb:241:in `assert_exists': unable to locate element,
using {:xpath=>"/html/body/div/div[2]/div/ul/li//*[#id=btn_WEBURL]", :tag_name=>
"a"} (Watir::Exception::UnknownObjectException)
from C:/Program Files/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.2
.2/lib/watir-webdriver/elements/element.rb:69:in `click'
from ft.rb:13
Is there a way to NOT open a new window every time I click on a link on Chrome, using watir-webdriver. Or any other solution to my problem.
Thanks
You can locate and use the other window:
browser.window(:title => "your popup window").use do
browser.button(:id => "close").click
end
see more examples: https://github.com/jarib/watirspec/blob/watir2/window_switching_spec.rb
I recognise that Google Chrome & Chromium aren't highly AppleScript enabled yet. But, I was wondering if there was a way to use the "System Events" to hide a particular window or tab?
Here is what I have so far ...
tell application "System Events"
tell process "Google Chrome"
repeat with theWindow in windows
set thePageName to title of theWindow
if thePageName contains "ABC" then
-- HIDE theWindow command here
end if
end repeat
end tell
end tell
I can access the window I wish to hide but cannot find the command to actually hide it.
Furthermore, if there is a way to repeat through the tabs within the window, that would be even better.
Thanks
System events can type keyboard commands for you. So look through the menu items of the application and see if there are any keyboard shortcuts to do what you want. For example, every application should have a "Window" menu. In the Window menu is a "Minimize" command with the keyboard shortcut "cmd-m". So you can use that shortcut to hide your windows. Just replace "-- HIDE theWindow command here" with...
keystroke "m" using command down
One other thing. For this to work you must make sure the application is frontmost before doing this so add the following to the beginning of your script.
tell application "Google Chrome" to activate