Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Frown

macrumors newbie
Original poster
Jul 18, 2009
5
0
I need to load a page in Safari in separate tabs/windows every 30 minutes in order to gather statistics, and I was wondering if anybody can help me out with a script for AppleScript to do this?

Also, if this is in the wrong section, I apologize. I am dealing very basic programming.
 

wafl iron

macrumors regular
Nov 16, 2007
183
0
I dont know if this works, but its probably on the right track or at least it can help you get somewhere

Code:
open_safari_window("https://www.macrumors.com")

on open_safari_window(my_url)
	tell application "Safari"
		repeat with i from 1 to 10
			# wake up safari
                        activate
			
			# make a new window
			make new document at end of documents
			
                        # set the URL of this new window
			tell document i
				set URL to my_url
			end tell

                        # sleep 1800 seconds (30 minutes)
			delay 1800
		end repeat
	end tell
end open_safari_window
 

Frown

macrumors newbie
Original poster
Jul 18, 2009
5
0
I dont know if this works, but its probably on the right track or at least it can help you get somewhere

Sorry, it won't let me compile it. I think your method should work though. I mean, it all makes sense.
 

craig1410

macrumors 65816
Mar 22, 2007
1,129
905
Scotland
Sorry, it won't let me compile it. I think your method should work though. I mean, it all makes sense.

It compiles and runs okay for me although it creates a new Safari window each time rather than a new tab.

Are you running Leopard (OS X 10.5.*) or are on an older version of OS X?

Regards,
Craig.
 

Frown

macrumors newbie
Original poster
Jul 18, 2009
5
0
It compiles and runs okay for me although it creates a new Safari window each time rather than a new tab.

Are you running Leopard (OS X 10.5.*) or are on an older version of OS X?

Regards,
Craig.

I'm running Tiger on a 1.83 GHz MacBook. Could that be the problem?

EDIT: I used it on my other MacBook, and it worked fine. Thank you very much, guys!
 

craig1410

macrumors 65816
Mar 22, 2007
1,129
905
Scotland
I'm running Tiger on a 1.83 GHz MacBook. Could that be the problem?

EDIT: I used it on my other MacBook, and it worked fine. Thank you very much, guys!

Hi,
Glad you got it working. Yes there are differences between Tiger and Leopard but I don't know what they are to be honest. I've come across issues of scripts working in Leopard but not in Tiger which is why I asked. I'm a beginner in Applescript myself but I often find that helping other people with a specific problem helps me to learn better than just sitting down doing artificial tasks all of my own.

I managed to get the above script working by creating new tabs rather than windows but I forgot to save it... Let me know if you want it to work with tabs rather than windows and I'll get it working again.

Cheers,
Craig.
 

Frown

macrumors newbie
Original poster
Jul 18, 2009
5
0
I managed to get the above script working by creating new tabs rather than windows but I forgot to save it... Let me know if you want it to work with tabs rather than windows and I'll get it working again.

Cheers,
Craig.

That would be great.
 

craig1410

macrumors 65816
Mar 22, 2007
1,129
905
Scotland
That would be great.

Okay, try this:

Code:
open_safari_window("https://www.macrumors.com")

on open_safari_window(my_url)
	tell application "Safari"
		activate
		set newDoc to (make new document with properties {URL:my_url})
		
		repeat with i from 2 to 10
			# sleep 1800 seconds (30 minutes)
			delay 1800
			tell window 1 to set current tab to (make new tab with properties {URL:my_url})
		end repeat
	end tell
end open_safari_window

Note that "Window 1" seems to represent the current window in focus so if you were to set the script running and then open another Safari window you will find that the new tabs start appearing in that instance of Safari rather than the original instance. I'm not familiar enough with Applescript to figure out how to prevent this. Maybe another user will be able to suggest something.

Anyway, I hope this helps.
Craig.
:)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.