applescript auto refresh for safari

Discussion in 'Mac Apps and Mac App Store' started by bizzit, Jan 16, 2010.

  1. bizzit macrumors newbie

    Joined:
    Jan 16, 2010
    #1
    ok so im very new to applescript but already a HUGE fan of the possibilities. i'm looking to write a script that will auto refresh a web page ive loaded on safari. if possible id like to be able to set it to a specific safari window so that i can continue you brows in a separate window. any suggestions
     
  2. BrownCoatMal macrumors newbie

    Joined:
    Jan 28, 2010
    #2
    I'm wondering about this too. I'd like to auto refresh a page

    Any answers?
     
  3. preste101, Sep 9, 2013
    Last edited: Sep 9, 2013

    preste101 macrumors newbie

    Joined:
    Sep 9, 2013
    #3
    Auto Refresh, yet continue to use Browser

    I wish I stumbled upon this thread earlier. I've just written this script up for you guys. If anyone needs help using it just reply here and I'll try my best to help you out!

    This is the link to the script from a Snippet host - Snipt.org:
    http://snipt.org/Aggif4/Default

    And here is the raw code if the snipt page is deleted:
    Code:
    property url_list : {"", "", "", "", ""}
    property _defaultTotalRefreshes : 0
    property _defaultTotalSeconds : 1
    
    set _numoftabs to (choose from list {"1", "2", "3", "4", "5"} with prompt "How many tabs will you have open for auto Refreshing?" default items "1" OK button name "This Many" cancel button name "Nevermind")
    
    --These two variables are very self explanatory
    set _total to the text returned of (display dialog "How many total refreshes?" default answer ¬
    	_defaultTotalRefreshes with title "Total")
    set _seconds to the text returned of (display dialog "How many seconds per refresh?" default answer ¬
    	_defaultTotalSeconds with title "Seconds")
    
    --Set the default seconds to the previously entered number so it will be remembered 
    --for the next time the user runs the script
    set _defaultTotalSeconds to _seconds
    set _defaultTotalRefreshes to _total
    
    if _numoftabs = false then --Determine if the user wants to quit
    	error "User canceled." number -128
    else
    	repeat with i from 1 to _numoftabs --Fill the list with urls
    		set item i of url_list to text returned of (display dialog "What website do you want to set for tab " & i & "?" default answer "http://" with title "Enter the WHOLE address (http:// too)")
    	end repeat
    	
    	tell application "Safari"
    		make new document
    		set winID to the id of window 1 --crucial for not crossing over to other window
    		repeat with j from 1 to _numoftabs --open that list in new tabs
    			set URL of tab j of window id winID to item j of url_list
    			if j is less than _numoftabs then --opens the amount of tabs specified
    				make new tab of window id winID
    			end if
    		end repeat
    		
    		-- HERE IS THE AUTO REFRESH PART
    		repeat with _count from 0 to _total
    			repeat with k from 1 to _numoftabs
    				set URL of tab k of window id winID to item k of url_list
    				delay _seconds
    			end repeat
    		end repeat
    	end tell
    	
    end if
    
     
  4. drewsof07 macrumors 68000

    drewsof07

    Joined:
    Oct 30, 2006
    Location:
    Ohio
    #4
    Here's a java script that does the same thing, just save to your bookmarks:

    Code:
    javascript:(function(p){open('','',p).document.write('%3Cbody%20id=1%3E%3Cnobr%20id=2%3E%3C/nobr%3E%3Chr%3E%3Cnobr%20id=3%3E%3C/nobr%3E%3Chr%3E%3Ca%20href=%22#%22onclick=%22return!(c=t)%22%3EForce%3C/a%3E%3Cscript%3Efunction%20i(n){return%20d.getElementById(n)}function%20z(){c+=0.2;if(c%3E=t){c=0;e.location=u;r++}x()}function%20x(){s=t-Math.floor(c);m=Math.floor(s/60);s-=m*60;i(1).style.backgroundColor=(r==0||c/t%3E2/3?%22fcc%22:c/t%3C1/3?%22cfc%22:%22ffc%22);i(2).innerHTML=%22Reloads:%20%22+r;i(3).innerHTML=%22Time:%20%22+m+%22:%22+(s%3C10?%220%22+s:s)}c=r=0;d=document;e=opener.top;u=prompt(%22URL%22,e.location.href);t=u?prompt(%22Seconds%22,60):0;setInterval(%22z()%22,200);if(!t){window.close()}%3C/script%3E%3C/body%3E')})('status=0,scrollbars=0,width=100,height=115,left=1,top=1')
     

Share This Page