Applescript NOOB

Discussion in 'Mac Programming' started by Revolume, Nov 19, 2010.

  1. macrumors newbie

    Sep 27, 2009
    I have never used AppleScript before, and I wanted to create a view bot (keeps refreshing webpage for views). I found one online that works perfectly, but if I want to change the URL, I have to open Applescript. The same goes for changing the refresh time (currently at every 2 seconds). Can I make it so that when the application opens, there is a simple dialog box with texts fields for both URL and refresh time? Here is what I am using now.

    on run
    end run

    on idle
    return 2
    end idle

    to do_the_thing()
    tell application "Safari"
    open location ""
    end tell
    end do_the_thing

    How can I do this?
  2. kanenas, Nov 20, 2010
    Last edited: Nov 20, 2010

    macrumors newbie

    Jun 20, 2008
    "display dialog"

    display dialog "..." default answer "" will display a dialog with a text input. choose from list {...} will present a dialog with a list box. Unfortunately, there isn't any way of getting multiple inputs in a single dialog without installing a third party scripting addition. The usual approach is to let the user enter all the necessary information in the single input, separated by some character (e.g. a comma or space) With URLs, a space character would work well.

    on getInput(refresh, |url|)
        set oldDelims to text item delimiters
        set text item delimiters to " "
        display dialog "Enter refresh time (if you wish to override it) and URL, separated by spaces" ¬
            default answer (refresh & |url| as string)
        set input to text returned of result
        if (count of input's text items) > 1 then
                set refresh to (text item 1 of input as integer)
                set |url| to (text items 2 through end of input) as string
            on error
                set |url| to input
            end try
                set refresh to input as integer
            on error
                set |url| to input
            end try
        end if
        set text item delimiters to oldDelims
        return {refresh:refresh, URL:|url|}
    end getInput
    (Note: use
     tags to delineate and format code, as above. If you ever post PHP code, use [php]. Other forums support other code tags, such as [html], but apparently not this one.)
    Also read Apple's documentation on [URL=""][FONT="Courier New"]display dialog[/FONT][/URL] and [URL=""][FONT="Courier New"]choose from list[/FONT][/URL].
  3. macrumors newbie

    Dec 1, 2010
    If you have multiple sites and you need to do a random refresh (which is more natural), you may want to create a text file and read the input from that file rather than setting it up directly in your script.

    That way, in the future, you simply modify your txt file if new URLs are to be added etc.

Share This Page