Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

uaecasher

macrumors 65816
Original poster
Jan 29, 2009
1,289
0
Stillwater, OK
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...
 

mysterytramp

macrumors 65816
Jul 17, 2008
1,334
4
Maryland
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
 

uaecasher

macrumors 65816
Original poster
Jan 29, 2009
1,289
0
Stillwater, OK
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
 

mysterytramp

macrumors 65816
Jul 17, 2008
1,334
4
Maryland
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
 

uaecasher

macrumors 65816
Original poster
Jan 29, 2009
1,289
0
Stillwater, OK
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

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
 

Attachments

  • Screenshot on 2009-07-01 at 3.57.07 PM.png
    Screenshot on 2009-07-01 at 3.57.07 PM.png
    77.1 KB · Views: 108

LtRammstein

macrumors 6502a
Jun 20, 2006
570
0
Denver, CO
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)".
 

mysterytramp

macrumors 65816
Jul 17, 2008
1,334
4
Maryland
"Desktop/untitled folder" is the path where to save the image

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
 

uaecasher

macrumors 65816
Original poster
Jan 29, 2009
1,289
0
Stillwater, OK
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
 

uaecasher

macrumors 65816
Original poster
Jan 29, 2009
1,289
0
Stillwater, OK
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
 

mysterytramp

macrumors 65816
Jul 17, 2008
1,334
4
Maryland
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
 

uaecasher

macrumors 65816
Original poster
Jan 29, 2009
1,289
0
Stillwater, OK
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
 

mysterytramp

macrumors 65816
Jul 17, 2008
1,334
4
Maryland
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
 

uaecasher

macrumors 65816
Original poster
Jan 29, 2009
1,289
0
Stillwater, OK
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
 

LtRammstein

macrumors 6502a
Jun 20, 2006
570
0
Denver, CO
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.