Very simple programming to browse the web - MacRumors Forums
Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 18, 2009, 02:46 PM   #1
Frown
macrumors newbie
 
Join Date: Jul 2009
Very simple programming to browse the web

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.
Frown is offline   0 Reply With Quote
Old Jul 18, 2009, 03:19 PM   #2
wafl iron
macrumors regular
 
Join Date: Nov 2007
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("http://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

Last edited by wafl iron; Jul 18, 2009 at 03:29 PM.
wafl iron is offline   0 Reply With Quote
Old Jul 18, 2009, 05:42 PM   #3
Frown
Thread Starter
macrumors newbie
 
Join Date: Jul 2009
Quote:
Originally Posted by wafl iron View Post
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.
Frown is offline   0 Reply With Quote
Old Jul 19, 2009, 07:27 AM   #4
craig1410
macrumors 6502a
 
Join Date: Mar 2007
Location: Scotland
Quote:
Originally Posted by Frown View Post
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.
__________________
MacBook Pro Retina 15.4", 2.3GHz, 16GB RAM, 500GB SSD; 24" Aluminium iMac, 2.4GHz, 4 GB RAM, 2 TB HDD
Time Capsule 500GB; iPhone 5 32GB Black/Slate; iPad Air 64GB WiFi
craig1410 is offline   0 Reply With Quote
Old Jul 19, 2009, 09:48 AM   #5
Frown
Thread Starter
macrumors newbie
 
Join Date: Jul 2009
Quote:
Originally Posted by craig1410 View Post
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!

Last edited by Frown; Jul 19, 2009 at 09:55 AM.
Frown is offline   0 Reply With Quote
Old Jul 19, 2009, 10:17 AM   #6
craig1410
macrumors 6502a
 
Join Date: Mar 2007
Location: Scotland
Quote:
Originally Posted by Frown View Post
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.
__________________
MacBook Pro Retina 15.4", 2.3GHz, 16GB RAM, 500GB SSD; 24" Aluminium iMac, 2.4GHz, 4 GB RAM, 2 TB HDD
Time Capsule 500GB; iPhone 5 32GB Black/Slate; iPad Air 64GB WiFi
craig1410 is offline   0 Reply With Quote
Old Jul 19, 2009, 02:32 PM   #7
Frown
Thread Starter
macrumors newbie
 
Join Date: Jul 2009
Quote:
Originally Posted by craig1410 View Post
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.
Frown is offline   0 Reply With Quote
Old Jul 19, 2009, 05:05 PM   #8
craig1410
macrumors 6502a
 
Join Date: Mar 2007
Location: Scotland
Quote:
Originally Posted by Frown View Post
That would be great.
Okay, try this:

Code:
open_safari_window("http://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.
__________________
MacBook Pro Retina 15.4", 2.3GHz, 16GB RAM, 500GB SSD; 24" Aluminium iMac, 2.4GHz, 4 GB RAM, 2 TB HDD
Time Capsule 500GB; iPhone 5 32GB Black/Slate; iPad Air 64GB WiFi
craig1410 is offline   0 Reply With Quote
Old Jul 19, 2009, 07:37 PM   #9
Frown
Thread Starter
macrumors newbie
 
Join Date: Jul 2009
Everything is working perfectly. Thanks, Craig!
Frown is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
iPod Touch: Any web browse does not refresh page back and forth? Nanasaki iOS 7 2 Feb 2, 2014 02:10 PM
Simple Programming rlketcham Mac Programming 1 May 14, 2013 12:06 AM
iPhone: tweak so that I can talk and browse the web TheShadowXX Jailbreaks and iOS Hacks 17 Mar 3, 2013 10:16 AM
Is there a way to browse the app store using a web browser? skidbubble Mac Applications and Mac App Store 1 Oct 15, 2012 09:39 PM

Forum Jump

All times are GMT -5. The time now is 07:18 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC