20i Reseller Hosting

Tweak this apple script please

Discussion in 'Services Wanted' started by philiporchard, Mar 30, 2019.

  1. philiporchard United Kingdom

    philiporchard Well-Known Member Acorn Supporter

    Joined:
    May 2007
    Posts:
    1,780
    Likes Received:
    74
    Hi,

    I'm trying to take screen grabs of a list of URLs.

    I'm doing it on a local machine - to ensure the grabs all look perfect.

    I've found an apple Script for Mac which does the job perfectly:
    https://mac.appstorm.net/general/ap...y-create-screenshots-from-a-list-of-websites/

    The only disadvantage is that it names the files webshot-1, webshot-2, rather than the URL of the page that the screen grab is of.

    I've had a little play with this - but to no avail.

    If anyone can help, that would be great.

    Thanks, Phil
     
  2. Domain Forum

    Acorn Domains Elite Member

    Joined:
    1999
    Messages:
    Many
    Likes Received:
    Lots
    articles.co.uk
     
  3. dee

    dee Well-Known Member Acorn Supporter

    Joined:
    May 2013
    Posts:
    1,528
    Likes Received:
    166
    this works i think :

    Code:
    --Variables
    set whichUrl to 1
    set fileNames to "webshot"
    set filename_text to ""
    
    --Get Number of URLs
    tell application "TextEdit"
        set theCount to the count of paragraphs of front document
    end tell
    
    --Repeat this for every URL
    repeat theCount times
      
        --Get the next URL
        tell application "TextEdit"
            set currentUrl to paragraph whichUrl of front document as text
        end tell
      
        --Open the URL in Safari
        tell application "Safari"
            activate
            set the URL of document 1 to currentUrl
          
            --Wait until it loads, then take a screenshot
            delay 5
    
            --set current url as variable to be able to strip text
            set the filename_text to currentUrl
          
            set filename_text to ((characters 8 thru -1 of filename_text) as string) --trim first characters of current url
            set filename_text to ((characters 1 thru -6 of filename_text) as string) --trim last chracters of current url
          
            set picPath to ((POSIX path of (path to desktop)) & fileNames & "-" & filename_text & ".jpg") as string
            do shell script "screencapture -tjpg " & quoted form of picPath
        end tell
      
        --Increase the counter for next time
        set whichUrl to whichUrl + 1
    end repeat
    play around with the character trim bit if your using mostly co.uk or whatever so your not writing full stops in the file name
     
    • Like Like x 1
    Last edited: Mar 31, 2019
  4. philiporchard United Kingdom

    philiporchard Well-Known Member Acorn Supporter

    Joined:
    May 2007
    Posts:
    1,780
    Likes Received:
    74
    Many thanks! I'll have a play tomorrow.