AppleScript and Automator help

Discussion in 'Mac Programming' started by uaecasher, Jun 30, 2009.

  1. macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #1
    Hello,

    I want to make an AppleScript or Automator run to make the following:


    take screen shot of window opening, click mouse, wait x seconds , take screen shots etc...
     
  2. macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #2
    Look here for the screen capture code.

    To open the folder and click the mouse, use System Events, something like this:

    Code:
    tell application "Finder"
    	activate
    	open folder "Macintosh HD:Applications"
    	tell application "System Events"
    		click at {100, 100}
    	end tell
    	delay 3
    end tell
    Does this help?

    mt
     
  3. thread starter macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #3
    Code:
    set save_location to  Desktop
      
    
    repeat with shotcount from 1 to 100
      do shell script "screencapture " & 
    Desktop/untitled folder  & "screen" & (shotcount as string) & ".pdf"
      delay (5) 
    end repeat
    
    tell application "Safari"
    	activate
    	tell application "System Events"
    		click at {100, 100}
    	end tell
    	delay 5
    end tell
    
    
    I keep getting syntax errors
    and how should i know the x and y coordinates of the point i want to click
     
  4. macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #4
    What specifically is your script?

    What specifically are the errors?

    What do you want to accomplish with the mouseclick?

    What is it you're trying to do?

    mt
     
  5. thread starter macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #5
    1) the code above is my script .

    2) Syntax Error: Expected expression but found end of line.

    3) well the click is to turn pages in pdf file in safari.

    4) taking screen shot of online book
     

    Attached Files:

  6. macrumors 6502a

    LtRammstein

    Joined:
    Jun 20, 2006
    Location:
    Denver, CO
    #6
    Code:
    repeat with shotcount from 1 to 100
      do shell script "screencapture " & 
    Desktop/untitled folder  & "screen" & (shotcount as string) & ".pdf"
      delay (5) 
    end repeat
    What is "Desktop/untitled folder"? Also, "(shotcount as string)" should probably be "(showcount as string)".
     
  7. thread starter macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #7
    "Desktop/untitled folder" is the path where to save the image
     
  8. macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #8
    The original script called "choose folder" then used that variable in the screencapture script. "Desktop/untitled folder" is not a valid path. Terminal will want a Posix path, something more like:

    '/Users/<your user name>/Desktop/untitled folder'

    It'll want the single quotes and it will expect that untitled folder already exist.

    You'll have to experiment where the turn page icon is. I used {100,100} as an example.

    If Safari can open a pdf, can it not save it to your hard disk? It seems like you're pursuing the hardest solution when something easier is available.

    mt
     
  9. thread starter macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #9
    well, it's not in pdf format but it's an online book, i found way to find the coordinates i can use the select screen shot (Command shift 4) and it will give me the axes of the point
     
  10. thread starter macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #10
    I get this error 'Expected expression but found unknown token'

    and it highlight the single quotes


    Code:
    set save_location to  '/Users/Fahad/Desktop/untitled folder'
      
    
    repeat with shotcount from 1 to 100
      do shell script "screencapture " & 
    '/Users/Fahad/Desktop/untitled folder'  & "screen" & (shotcount as string) & ".pdf"
      delay (5) 
    end repeat
    
    tell application "Safari"
    	activate
    	tell application "System Events"
    		click at {100, 100}
    	end tell
    	delay 5
    end tell
     
  11. macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #11
    Terminal wants the single quotes, but Applescript doesn't understand single quotes.

    Try:

    Code:
    set save_location to  "'/Users/Fahad/Desktop/untitled folder'"
    If that doesn't work, use double quotes and then:

    Code:
    set save_location to quoted form of save_location
    It'll do the same thing.

    mt
     
  12. thread starter macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #12
    hey, this is UAECASHER my account got stolen so I'm writing from this account,

    this is my final code

    Code:
    
    set save_location to ¬
    	"'Users/Fahad/Desktop/ss'"
    
    repeat with shotcount from 1 to 2
    	do shell script "screencapture " & ¬
    		quoted form of POSIX path of save_location ¬
    		& "screen" & (shotcount as string) & ".jpg"
    	delay (10) -- delay 3 second  
    	
    	
    	tell application "System Events"
    		click at {1360, 450}
    	end tell
    	delay 3
    	
    	
    end repeat
    
    
    it take screen shot but it's saving it at my hard drive root i.e (Macintosh HD)

    and it don't click
     
  13. macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #13
    The reason your screen shots are appearing in the wrong directory is because your variable "save_location" is fine, but then you add "the quoted form of Poxix path of save_location" -- you're gilding the lily and the computer doesn't know what's up.

    if "ss" is a folder, save_location should end with a "/". So ...

    Code:
    set save_location to ¬
    	"'Users/Fahad/Desktop/ss/'" -- assuming ss is a folder
    
    repeat with shotcount from 1 to 2
    	do shell script "screencapture " & save_location ¬
    		& "screen" & (shotcount as string) & ".jpg"
    	delay (10) -- delay 3 second  
    	
    	
    	tell application "System Events"
    		click at {1360, 450}
    	end tell
    	delay 3
    	
    	
    end repeat
    Why click isn't working, you got me. System Events is always a last resort and my guess is a) you're trying to grab pages from the amazon.com web site, and b) their programmers figured somebody might do this and are handling mouseclicks just differently enough to prevent someone from pulling this off.

    I realize it's way too analog for the 21st century, but you might try a library.

    mt
     
  14. thread starter macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #14
    no it does not click anywhere, like if i try to click on folder. and the location is still wrong even after adding / at the end
     
  15. thread starter macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
  16. macrumors 6502a

    LtRammstein

    Joined:
    Jun 20, 2006
    Location:
    Denver, CO
    #16
    What I recommend, and I do this all the time, is to have the Applescript editor record your clicks. So basically do what you want your script to do once. This way you can see the code generated by the computer and adapt it.
     

Share This Page