tell application "Google Chrome" to activate
delay 0.5
tell application "System Events"
tell process "Google Chrome"
click at {1067, 79}
click at {1026, 220}
end tell
end tell
here is my applescript, I tried to open and extension by first click in chrome and then second click to download the video inside of the extension, however, only the first command was executed and the second return "missing value". I don't know why. I've also tried add a delay between the two command, it still doesn't work. Any one can help?
tell application "Google Chrome" to activate
delay 0.5
tell application "System Events"
tell process "Google Chrome"
click at {1067, 79}
delay 1
click at {1026, 220}
end tell
end tell
if this is what you mean^ then try this:
tell application "Google Chrome" to activate
delay 0.5
tell application "System Events"
tell process "Google Chrome"
click at {1067, 79}
end tell
end tell
delay 0.5
tell application "Google Chrome" to activate
tell application "System Events"
tell process "Google Chrome"
click at {1026, 220}
end tell
end tell
Turns out that if it "can't click" it will return "missing value" for a given coordinates.
This seems to happen for instance when I click into a chrome browser. If I click into Safari, it works great. If I click into a firefox, it returns and says it clicked, but doesn't actually do anything in the browser. Weird.
Workaround: Use 3rd party app MouseTools to click instead. Refs:
https://stackoverflow.com/a/12887429/32453
https://stackoverflow.com/a/22595044/32453
Though I suppose you could write your own obj-c code to do it as well, etc.
Related
on alfred_script(q)
tell application "Google Chrome"
if it is closed then
activate
end if
else
make new window
tell application "System Events" to set frontmost of process "Google Chrome" to true
activate
end else
end tell
end alfred_script
What is wrong is my appleScript code
I just want to open new terminal if google chrome is open otherwise just run the google chrome.
It will be a alfred work flow.
You don't need to work with process of an application.
on alfred_script(q)
tell application "Google Chrome"
if its running is true then make new window
activate
end tell
end alfred_script
Note: you can omit is true as well. if its running then make new window
You don't need any of your conditions. This will launch the app and make a new window if it's not running. If it is running, it will be brought frontmost and a new window will be made.
tell application "Google Chrome"
activate
make new window
end tell
That said, you will probably end up with too many blank windows. This will check whether Google Chrome is already running. If it is, it will bring it frontmost. If there's an existing window or there's no window a new one will be created. If Chrome is not running it will be launched with a new window (its default start state).
tell application "System Events" to (name of processes) contains "Google Chrome"
set chromeRunning to result
tell application "Google Chrome"
activate
if chromeRunning then
make new window
end if
end tell
How can the youtube be opened in safari private mode?
I have tried this, but it is not working:
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
click menu item "New Private Window" of menu "File" of menu bar 1
open location "https://www.youtube.com" -- this will open default browser
end tell
end tell
My default browser is Chrome, and it opens youtube in chrome not in safari private mode.
How to fix this?
The following example AppleScript code works for me:
For Safari use:
activate application "Safari"
tell application "System Events" to ¬
click menu item "New Private Window" of ¬
menu "File" of menu bar 1 of ¬
application process "Safari"
tell application "Safari" to ¬
set URL of current tab of ¬
front window to "https://www.youtube.com"
Note: If one prefers, each of the two tell statements can be all on a line of its own by removing the ¬ line continuation character and the invisible linefeed character that follows.
For Google Chrome use:
activate application "Google Chrome"
tell application "System Events" to ¬
click menu item "New Incognito Window" of ¬
menu "File" of menu bar 1 of ¬
application process "Google Chrome"
tell application "Google Chrome" to ¬
set URL of active tab of ¬
front window to "https://www.youtube.com"
Note: If one prefers, each of the two tell statements can be all on a line of its own by removing the ¬ line continuation character and the invisible linefeed character that follows.
Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors.
I don't really have a better solution for Safari than the one offered by #user3439894. The only thing I would have done differently would be to make the new private window using this code (which is probably "6 of 1 or 1/2 a dozen of the other")
tell application "Safari" to activate
tell application "System Events" to tell its application process "Safari"
set frontmost to true
keystroke "n" using {shift down, command down}
end tell
However, you may prefer this solution for Google Chrome because it does not require the use of System Events and it does not require Google Chrome to be active or frontmost.
tell application "Google Chrome"
set incognitoWindow to (make new window with properties {mode:"incognito"})
repeat while loading of active tab of incognitoWindow
delay 0.1
end repeat
set URL of active tab of incognitoWindow to "http://youtube.com"
end tell
tell application "Opera"
try
make new window with properties {mode:"incognito"}
end try
set URL of active tab of front window to "https://yoururl.com"
end tell
I wrapped make new window with properties {mode:"incognito"} in try because I get an error "Opera got an error: AppleEvent handler failed." number -10000 because i use Opera browser.
It is not necessary when using Google Chrome.
I need to copy some data from Numbers and move them over to a GUI in Google Chrome browser. I need to click a button first to open up a textbox before pasting. Right now it will only copy the data from Numbers and will throw an error System Events got an error: Can’t get application process "Google Chrome" of process "Google Chrome".
Here is my script:
tell application "Numbers" to activate
tell application "System Events"
tell process "Numbers"
keystroke "c" using command down
end tell
end tell
delay 0.2
tell application "Google Chrome" to activate
tell application "System Events"
tell process "Google Chrome"
click button "Add a New Value" of application process "Google Chrome"
keystroke "v" using command down
keystroke return
end tell
end tell
The error message says you are referencing process "Google Chrome" of process "Google Chrome" which occurs in the click button line.
tell process "Google Chrome"
click button
is the same as
click button of process "Google Chrome"
so
tell process "Google Chrome"
click button "Add a New Value" of application process "Google Chrome"
is the same as
click button "Add a New Value" of process "Google Chrome" of process "Google Chrome"
which causes the syntax error.
The solution is to change the line to
click button "Add a New Value"
I'm trying to make an applescript that will click in the same spot over and over again buy i can't get it to work.
tell application "Safari"
activate
end tell
repeat
tell application "System Events"
click at {1, 1}
end tell
delay 1
end repeat
You will have to tell System Events in which application the click should be executed, like the following example (this should theoretically open your bookmarks, if you have a maximised Safari window):
tell application "System Events" to tell application process "Safari"
click at {5, 75}
end tell
On a side note, you should think about a better title for your question next time, this is too general.
How can I tell Chrome or Firefox to reload the document in the top window? Here's what I'm using for Safari:
osascript -e '
tell application "Safari"
activate
do JavaScript "history.go(0)" in document 1
end tell
'
Here's the code for Chrome:
tell application "Google Chrome"
tell the active tab of its first window
reload
end tell
end tell
Or more concisely:
tell application "Google Chrome" to tell the active tab of its first window
reload
end tell
I do not think Firefox or Chrome have special Applescript support, but you can send the keystrokes (Cmd-R) to refresh the page:
tell application "Firefox"
activate
tell application "System Events" to keystroke "r" using command down
end tell
Here's another way to do it in Safari without using JavaScript:
tell application "Safari"
tell its first document
set its URL to (get its URL)
end tell
end tell
Automator
Open Automator and choose a New Document
Choose Service
Set Service receives to no input
Choose Run AppleScript action from the action list.
Paste the following code in the script:
tell application "Google Chrome" to tell the active tab of its first window
reload
end tell
Save the the service, for example, using the name Chrome Refresh
System Preferences
Open System Preferences > Keyboard
In the Shortcuts tab, choose Services
Assign a new shortcut
The following answers above work well but using them result in DevTools refreshing in a new tab if it was the last tab/window in focus. I don't want DevTools to refresh in a new tab, I just want the first tab to refresh regardless of last focus/active and this worked well for me. Leaving for someone searching for this use case as well.
tell application "Google Chrome"
activate
tell application "System Events"
tell process "Google Chrome"
keystroke "r" using {command down, shift down}
end tell
end tell
end tell