Hi I’m brand new to applescript and to this forum. So what I want to do is write a script that will automatically open up a safari window with sever different webpages in tabs. I have figured out how to open a safari window to a specific website but cannot open up a tab. Right now what I was trying to do was use the “system event” application to use a keystroke to open a tab but it is not really working. This is what I have so far.
tell application "Safari"
make new document with properties {URL:"http://www.google.com"}
tell application "System Events"
keystroke "t" using {command down}
end tell
end tell
it opens up the shortcut command t for the system events and not for safari.
You have to bring the target application frontmost before using UI elments e.g
tell application "Safari"
activate
make new document with properties {URL:"http://www.google.com"}
tell application "System Events"
keystroke "t" using {command down}
end tell
end tell
For opening pages in multiple tabs I use this
property URLlist : {"http://www.apple.com", "http://www.macscripter.net"}
activate application "Safari"
delay 1
load_page_new_Tab(first item of URLlist, false)
repeat with i from 2 to (count URLlist)
load_page_new_Tab(item i of URLlist, true)
end repeat
if result then
tell application "System Events"
tell process "Safari" to click menu item 5 of menu 1 of menu bar item 8 of menu bar 1
end tell
end if
on page_loaded(timeout_value)
delay 2
repeat with i from 1 to timeout_value
tell application "Safari"
if (do JavaScript "document.readyState" in document 1) is "complete" then
return true
else if i is timeout_value then
return false
else
delay 1
end if
end tell
end repeat
return false
end page_loaded
on load_page_new_Tab(theURL, tb)
if tb then tell application "System Events" to tell process "Safari" to keystroke "t" using command down
delay 1
tell application "Safari" to open location theURL
page_loaded(20)
end load_page_new_Tab
tell application “Safari”
activate
my new_tab()
open location URL1
my new_tab()
set the URL of document 1 to URL2
my new_tab()
set the URL of document 1 to URL3
end tell
on new_tab()
tell application “Safari” to activate
tell application “System Events”
tell process “Safari”
click menu item “New Tab” of menu “File” of menu bar 1
end tell
end tell
end new_tab
my problem is that when i emailed the script to my friend and loaded it on his Applescript it gave him an error that said [System Events got an error: NSReceiverEvaluationScriptError:4]