PDA

View Full Version : AppleScript and Automator help




uaecasher
Jun 30, 2009, 02:30 AM
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
Jun 30, 2009, 06:49 PM
Look here (http://www.macosxhints.com/article.php?story=20030115080027106) for the screen capture code.

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

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
Jul 1, 2009, 01:36 AM
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
Jul 1, 2009, 05:07 AM
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
Jul 1, 2009, 06:59 AM
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

LtRammstein
Jul 1, 2009, 01:46 PM
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)".

uaecasher
Jul 1, 2009, 02:11 PM
"Desktop/untitled folder" is the path where to save the image

mysterytramp
Jul 1, 2009, 08:14 PM
"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
Jul 2, 2009, 03:59 AM
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
Jul 2, 2009, 05:58 AM
I get this error 'Expected expression but found unknown token'

and it highlight the single quotes


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
Jul 2, 2009, 07:18 PM
Terminal wants the single quotes, but Applescript doesn't understand single quotes.

Try:

set save_location to "'/Users/Fahad/Desktop/untitled folder'"

If that doesn't work, use double quotes and then:

set save_location to quoted form of save_location

It'll do the same thing.

mt

uaecasher
Jul 5, 2009, 09:08 AM
hey, this is UAECASHER my account got stolen so I'm writing from this account,

this is my final 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
Jul 5, 2009, 01:00 PM
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 ...

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
Jul 14, 2009, 05:23 AM
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

uaecasher
Jul 16, 2009, 04:15 PM
any help please?

LtRammstein
Jul 16, 2009, 05:04 PM
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.