Sendkeys
|
|
Thread rating:  |
Vince - 30 Aug 2005 05:45 GMT I had posted this message earlier to the Perl Beginners group: ********** Here's the situation:
Some dude working in my company needs a program that does this-
- There are over a 100 PDF files in some folder on a Mac Machine - The program to be written is supposed to invoke Adobe Acrobat Professional 7 (Mac version) and open each file from the directory - Once each file is opened in Acrobat 7, it is supposed to push Alt + E (or similar) and then 'n' (or similar) in order to enable commenting on the PDF file. - The program is then supposed to push Alt +F and then 'S' to save the file - This is to happen for all the files in that folder.
Someone supposedly told the dude that this script in Perl was easy to write! But, un/fortunately, I have no idea where to begin. All I know is that, if I am doing it on a PC, I need to add the Win32 package and then study sample programs which should get me going some place. But, I don't know if Win32 would work on Mac or if there is an easier way to approach this!
I would be grateful for suggestions / directions on how to proceed. **********
I was pointed to this group and this is what I think I need to do:
a) Find the equivalent of Win32 package for Mac b) Write the program
But, here are my other concerns:
a) I've pretty much never worked on a Mac and don't possess one. In order to develop programs I use a PC. I was wondering if Macperl could be simulated on a PC?
Thanks for any advise.
Vince
Iyanaga Nobumi - 30 Aug 2005 12:53 GMT Hello Vince,
I don't have Adobe Acrobat Pro, and I don't know how it is scriptable. Even if it is not very scriptable, it should be able to open files with a script, and it should be possible to send the "sendkeys" commands that you describe with the user interface scripting. But then, it would be simpler to use AppleScript than Perl. I think the best place to ask such questions is the MacScripting mailing list <http://listserv.dartmouth.edu/scripts/ wa.exe?SUBED1=macscrpt&A=1>. But to develop AppleScript scripts, you should use a Mac...
Good luck, and Best regards,
Nobumi Iyanaga Tokyo, Japan
Lola Lee - 30 Aug 2005 13:28 GMT re are my other concerns:
> a) I've pretty much never worked on a Mac and don't possess one. In order to > develop programs I use a PC. I was wondering if Macperl could be simulated > on a PC? I would suggest, at the very least, that your company get you a Mac Mini and a KVM switch so that you can switch between your PC and the Mac, using the same monitor/keyboard/mouse. It would be unwise to release a program without having tested it on a computer setup for which it was written, wouldn't it?
 Signature Lola - mailto:lola@his.com http://www.lolajl.net | Blog at http://www.lolajl.net/blog/ Freedom is not free. I'm in Bowie, MD, USA, halfway between DC and Annapolis.
Daniel T. Staal - 30 Aug 2005 14:14 GMT > a) I've pretty much never worked on a Mac and don't possess one. In order > to develop programs I use a PC. I was wondering if Macperl could be > simulated on a PC? I'm leaving the rest of the answers; I can check if Acrobat is scriptable when I get home though.
I just wanted to say this: If what you were talking about were a normal Perl script, that is: it stayed within what perl does on its own, then sure. A Perl environment is a Perl environment, basically. If you really wanted to be sure you could put a free Unix on the PC (Darwin, if you wanted to be absolutely sure...), and test on that.
However, you are mostly talking about programming the Mac, Perl is just the language you have chosen (and it may not even be the right one for the job!), so you really would need to test it on a Mac.
Daniel T. Staal
--------------------------------------------------------------- This email copyright the author. Unless otherwise noted, you are expressly allowed to retransmit, quote, or otherwise use the contents for non-commercial purposes. This copyright will expire 5 years after the author's death, or in 30 years, whichever is longer, unless such a period is in excess of local copyright law. ---------------------------------------------------------------
Daniel Staal - 31 Aug 2005 00:29 GMT --As of Tuesday, August 30, 2005 9:14 AM -0400, macosx@perl.org is alleged to have said:
> I'm leaving the rest of the answers; I can check if Acrobat is scriptable > when I get home though. --As for the rest, it is mine.
Well, I said I'd answer this when I got home. I've got Acrobat 6 Pro, so there may be more features in the newer version.
Acrobat itself is not AppleScriptable (other than using the UI scripting capability). However, it does have an automation center, where you can specify full job flows using any option you can normally use. (Look under 'Advanced' for 'Batch Processing'.) This should be enough to do your job.
Also, Distiller, which comes with the pro version, *is* AppleScriptable, and can do most basic conversions for you. I don't see an option to do what you need in my version, but it may be worth looking.
It may also be worth checking if Automator can do anything; it can't with mine, but version 6 came out before Automator did.
Daniel T. Staal
--------------------------------------------------------------- This email copyright the author. Unless otherwise noted, you are expressly allowed to retransmit, quote, or otherwise use the contents for non-commercial purposes. This copyright will expire 5 years after the author's death, or in 30 years, whichever is longer, unless such a period is in excess of local copyright law. ---------------------------------------------------------------
Vince - 31 Aug 2005 08:58 GMT Thankyou everybody for all the details. I learnt a lot in the past 2 days!!
This is the solution we've come up with: First I checked (upon Ian's suggestion) if I could sompare the two PDF files (one with commenting not enabled and the other with commenting enabled) and see if I could somehow insert the instructions in the PDF file directly. This proved futile (may be I am too stupid).
So, I started reading up on Apple Script, Mac::glue (which looks easy but is rather hard when you use Macperl because of the many clicks needed to run something). I got to the stage where I could invoke Acrobat but soon after the Mac machine would get stuck!! So, aborted!
But, during my brief flirtation with Mac OSX, I discovered that it could actually talk to a PC!! Meaning, Mac OSX shared folders are accessible to PCs and vice versa. With this brilliant discovery, I switched back to homeground (PC and Win32::GuiTest) and voila! Job done. The Perl program (for the PC) does this exactly. I'll have to do the networking (set up the shared folders) and other customizations now but they idea is working.
Thanks everybody for the response.
Vince
> --As of Tuesday, August 30, 2005 9:14 AM -0400, macosx@perl.org is alleged > to have said: [quoted text clipped - 29 lines] > local copyright law. > --------------------------------------------------------------- Joel Rees - 30 Aug 2005 15:40 GMT http://www.apple.com/macosx/features/applescript/
You'll find links to most of what you need there. The rest will be on Adobe's site, or on AppleScript mail lists.
As has been mentioned, there is probably no reason to resort to perl and the Carbon API.
> I had posted this message earlier to the Perl Beginners group: > ********** [quoted text clipped - 44 lines] > > Vince Chris Nandor - 30 Aug 2005 19:21 GMT > Some dude working in my company needs a program that does this- > [quoted text clipped - 9 lines] > > Someone supposedly told the dude that this script in Perl was easy to write! This is likely fairly simple to do in Perl, with Mac::Glue, as long as the app is "scriptable" and as long as it can do what you want to do via Apple events, and as long as you can figure out HOW to do those things.
You can use AppleScript too, but I find Mac::Glue to be much easier to use, once you get the hang of it, since you can handle your logic flow and filesystem accesses much easier in Perl. Note that AppleScript will not be able to do something (in general) that Mac::Glue cannot do.
If you're running Tiger with the default Perl, you already have Mac::Glue installed, though you may wish to update it. If yes to Toger and no to updating Mac::Glue, you will need to run this first:
cd /System/Library/Perl/Extras/bin/ sudo ./gluedialect sudo ./gluescriptadds sudo ./gluemac '/System/Library/CoreServices/System Events.app' sudo ./gluemac /System/Library/CoreServices/Finder.app
And then the line above becomes something like:
sudo ./gluemac /Applications/Acrobat\ Professional
Else, after installing/updating Mac::Glue, just do:
sudo gluemac /Applications/Acrobat\ Professional
As I don't have the app in question, I can only guess how to do what you ask; it's different for every app. So below I give some guesses.
I see the 6.0 dictionary here:
http://macscripter.net/app_dictionaries/dictionary.php?id=196_0_1_0_C
It has no real clues; you might need to get into UI scripting, which is far more of a pain. You can tell the UI to hit a key combination, or select a menu, type a letter, and so on. The below assumes you won't need to do that.
use File::Spec::Functions; use Mac::Glue ':all'; my $dir = '/Users/pudge/Desktop/PDFs'; # using Safari for testing ... it opens each PDF, and closes it my $acrobat = new Mac::Glue 'Safari'; #'Acrobat Professional'; # etc. $acrobat->activate;
opendir my $dh, $dir or die "Can't open $dir: $!"; chdir $dir or die "Can't chdir $dir: $!"; for my $file (readdir $dh) { # or whatever ... next unless $file =~ /\.pdf$/i && -f $file;
my $pdf = $acrobat->open($file);
## ideally, $pdf will contain a reference to the just-opened ## document, but not for every app, so as a backup: $pdf ||= $acrobat->obj(window => 1); # get front window ## the above could also properly be: # $pdf ||= $acrobat->obj(document => 1, window => 1);
## no idea how to do this part; see "gluedoc $appname" on the ## command line for docs for the app, here's a wild guess; ## if someone could show me the AppleScript dictionary for the ## app, I could take a look; this is the part that may need to ## be done with UI scripting # $pdf->prop('commenting')->set(to => 1);
## usually, you can close "with saving," but you may ## need to save explicitly, or you vice versa (again, ## app-dependent); the combined close "with saving" ## is the most efficient method # $pdf->save; $pdf->close(saving => enum('yes')); }
 Signature Chris Nandor pudge@pobox.com http://pudge.net/ Open Source Technology Group pudge@ostg.com http://ostg.com/
|
|
|