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

juzernejm

macrumors member
Original poster
Mar 13, 2015
51
3
Hi again
I know you'll point me to the user manual of AppleScript but I'll try anyway for the last time.

I made a simple script in AppleScript for Acrobat Professional Pro to make a couple of menu items clicks to ocr an image and save it as plain text.

Code:
tell application "System Events"
    tell application process "Acrobat"
        tell application "Adobe Acrobat Pro" to activate
        click the menu item "Recognize Text Using OCR..." of menu 1 of menu item "OCR Text Recognition" of the menu "Document" of menu bar 1
        delay 2.4
        click button "OK" of window "Recognize Text"
        delay 2.4
        click the menu item "Text (Plain)" of menu 1 of menu item "Text" of menu 1 of menu item "Export" of the menu "File" of menu bar 1
        click button "Save" of window "Save As"
    end tell
end tell
end

This runs fine one one mac and doesn't in another one which has the same OS (Yosemite)
The only difference is that on the mac that doesn't work the language and versione of Acrobat are different but I've changed the menu names in the code to Italian (and checked the spelling) and also made sure the process name was right.

I'm getting this error:
error "System Events ha trovato un errore: Impossibile ottenere " number -1728 from process "AcrobatAcrobat"
it says System Events found an errore: Impossible to get ...
 
Hmmm... which version of Acrobat are you using? I don't see that menu item in my copy.

User interface scripting tends to be *very* clunky. I tend to use it as an absolute last resort, and even then under protest! You just need an app update to change the name or position of something and all your work goes up in a puff of smoke.

You might want to look at executing some JavaScript from your Applescript. It's not *much* nicer than UI scripting, mind, just slightly. Like I say, I don't seem to have that menu item in my copy of Acrobat, but to demonstrate the kind of thing I mean:

Code:
tell application "Adobe Acrobat Pro"
   tell document 1
       do script "app.execMenuItem('SaveAs');"
   end tell
end tell

There's some further info here:

https://acrobatusers.com/tutorials/executing_menu_items_from_javascript

Hope that's of some help!

r.
 
Thankyou very much superscape!
That's very helpful. I had the feeling that AppleScript isn't that used because I'm finding it hard to find instructional material. And now you are confirming my thoughts, in a sense. Even though I admit that most of the time the fault is mine, and not of the script (99% of the times) :p I think I'll have to take a look at JavaScript.

But I want to be sure to what language dedicate time (cause I don't have much left after a day at work) So I'm trying to understand what might be the best way to go about it. I'm a graphic designer working on a Mac and I know the software I use for work (Adobe mostly) are scriptable with JavaScript. But I thought that AppleScript controls these applications and also the Mac it self. So my thinking was to go with that. But I find even the most simple thing to be so incredibly hard. Lines and lines of code for the most stupid thing).

Since I like most user-interface programs, I'm thinking to give a try at Xcode also (4Gb beast). From what I read, AppleScript Studio (which is a more visual application to build applescripts) is integrated in Xcode so I'll give it a try. Then if I don't understand even that, I think I'll surrender and I have to pay for what I need. So frustrating though that we are stuck in many things just because we don't have installed in our brain the f.. program that makes us do what we want. Well at least this is "good for the economy" :D
 
Last edited:
Hi there,

Sounds like you're in the exact same situation I found myself in over 10 years ago. I was a graphic designer and I taught myself to code in any quiet times in the hopes of making the busy times easier. I've made a career of it ever since.

If you're looking to save yourself time in your day-to-day work (which I assume is in Adobe Creative Suite on the Mac) then AppleScript is absolutely the right way to go. Don't be put off by the example above - Acrobat is the exception to the rule. Most other Adobe CC apps are very AppleScriptable. I'll try to give you a few pointers...

  • Get a copy of Script Debugger (http://latenightsw.com/sd4/) and use it to write your scripts. It'll help you see what's going on and is much nicer than Script Editor / AppleScript Editor. Xcode is probably overkill for now and may well scare you off!
  • Always refer the scripting dictionary of an app when you're stuck. You can do this from Script Debugger.
  • If you do a lot of work with PDF then there are some command line tools which will help you e.g. pdfinfo, exiftool, pdftk. You can call these from AppleScript if/when necessary. I'd get reasonably confident with AppleScript first though.
  • I often find that a project requires me to work in a number of languages. There may be bits of AppleScript, shell scripts, Javascript, Objective-C... even Python (under protest!) etc... No language is the best choice for everything. Don't think that just because something can't be done in language x then you have to dump it and switch to language y.
  • It certainly won't hurt you to learn some other languages. If I was you I'd get reasonably confident in AppleScript then take a look at shell scripting (bash) and some JavaScript. If you're still feeling brave after that, have a look at Swift/Objective-C in Xcode.
  • A good way to learn is to look at other people's scripts. Take them apart. Learn how they work. Try altering them to do something slightly different.
  • There's a good beginner's tutorial here: http://macosxautomation.com/applescript/firsttutorial/index.html

You can always ask here if you get stuck. There are some pretty good scripters as regular members.

Good luck
r.
 
...just as a side note, AppleScript Studio is no more. However, you *can* build AppleScript based apps in Xcode. You'll find it harder that writing a script in Script Debugger. It's certainly not a 'visual method' of building scripts by any means.

The main reason to use Xcode is if you want create an app which includes windows, tables, menus etc. Although it's not *essential* to use Xcode for that, it *is* the most common way of doing it. Be under no illusions, that's harder work than knocking out a quick AppleScript in Script Debugger!
 
I saved your messages. They are full of infos I really needed. Thanks for the help, superscape.

in the hopes of making the busy times easier

That is exactly the situation I'm in. From what I'm seeing, I could make a lot of work easier. But, for the moment, all I can do are simple stuff with Automator or some simple scripts. I'm reading more than one book (on AppleScript) but it is not sticking. Maybe it is because I read after work (when the brain is off). I was thinking at this point to get a course/class here where I live, thinking that working with others might speed things up. But I'm not finding any. I also googled to see if I could get help (by paying) from someone online but found nothing. In forums except rare occasions (like this) it is not working either.
Sometimes I think that even if it seems I'm not progressing, maybe I am. It is like learning to ride the bike: it just takes time and a lot of falling at the beginning. Anyway [whining mode: off] :D
One last question: I heard a few times good words about FileMaker. Have you ever used it (maybe in Indesign to automate the layout of a catalogue..). I work a lot with a huge collection of images and description that I import in a layout in Indesign. But I do all this manually. I succeeded a few times using Excel to generate a csv of the content to import. But maybe there are better ways...
 
It is like learning to ride the bike: it just takes time and a lot of falling at the beginning. Anyway [whining mode: off] :D

That's exactly it! Certainly in the beginning of learning any language, you'll find you make a lot of mistakes. But making mistakes, figuring out what was wrong and then fixing it is a great way to learn. Feel free to ask questions here. There are some good AppleScripters here. Always try to post the code you're having problems with along with what you're trying to do, and what's going wrong. Usually someone will be able to help.

One last question: I heard a few times good words about FileMaker. Have you ever used it (maybe in Indesign to automate the layout of a catalogue..). I work a lot with a huge collection of images and description that I import in a layout in Indesign. But I do all this manually. I succeeded a few times using Excel to generate a csv of the content to import. But maybe there are better ways...

You've probably asked the wrong person here. I *do* have experience of FileMaker and I loathe it with a passion. I suppose, if I'm being generous, that FileMaker's okay if you don't know much about databases and want something that's comparatively easy to pick up - and also the database will never get very big and won't be business critical. In my personal experience, however, databases that start out small and not business critical have a habit of growing into big databases that *are* business critical.

If I was designing a database that *is* going to be big and/or business critical then I'd be looking at some form of SQL. Either MySQL (usually my preferred option), Microsoft SQL or Postgresql. You'll be on another steep learning curve if you choose one of those, but it'll be worth it in the long run.

Once you understand MySQL or similar then it's relatively simple to write a script to dump data out as XML. And InDesign has an XML import option...
 
  • Like
Reactions: juzernejm
Thanks superscape (and excuse my late reply)
There are some good AppleScripters here. Always try to post the code you're having problems
I hope to gain their trust one day and get some help.
I already have this problem I'm trying to solve: https://forums.macrumors.com/threads/change-the-modified-date-of-a-folder-applescript.1891206/

As for the detailed answer about FileMaker:
I'm realizing that I don't have time to dedicate to all this (programming). I already do many other things and programming requires time and dedication. Unfortunately I don't have it.
I hope in the future we invent a faster way to program the computer. Or even better.. create a structure where people share their skills and collaborate with each-other instead of trying to learn everything by them selves (wasting time and getting things wrong most of the time).
 
I think for your other issue you need to look at the Windows server in question and perhaps ask on a more Windows centric site. If, however, you were doing this on a local folder on your Mac, or on a Mac server then I'd recommend a short shell script such as:

Code:
find /Path/To/Your/Folder/Goes/Here -exec touch "{}" \;

...this would change the mod date of the folder and all its contents to the current date. Once you have that, its relatively simple to include that in an applescript if you need to, as follows:

Code:
set theFolder to choose folder with prompt "Please choose a folder"
do shell script "find " & quoted form of POSIX path of theFolder & " -exec touch \"{}\" \\;"

...all I'm doing in the latter example is using AppleScript to let the user choose a folder with a nice dialog. Then I use "do shell script" to execute a bash command.
 
this would change the mod date of the folder and all its contents to the current date
Thanks superscape. I needed this to take the date of the last modified file inside the folders, not the current date. But I guess it'll not work if I don't have privileges from the Windows machine. So I think I have to give up on this because I don't know how to do this on Windows.
 
Just to return in topic.
I'm trying to do a script for Acrobat 9 Pro. I have read a lot about libraries etc but I can't understand it. I found nothing useful online and I don't know what to do, or who to ask. I'm not trying to get the script without doing nothing. I hope to understand from it and not ask again.

I have a 2-pages pdf document that I always do the same things:
• I delete page 2;
• rotate (the page I'm left with) 90° clockwise;
• ⌘⇧T to crop it (left: 210mm top, buttom and right 0mm)
• Save it with another name. (and close it).

Can I do something like this in AppleScript?

Any help or suggestion will be helpful and I thank you for the time you'll dedicate to this.
 
Hi,

Okay, I'll set you off in the right direction. Firstly, Acrobat has poor support for AppleScript. It's usually better to use AppleScript to execute a JavaScript. Silly, I know. One of Adobe's many oversights...

So, to delete a page you can do this:

Code:
tell application "Adobe Acrobat Pro"
   tell front document
       do script "this.deletePages(0);"
   end tell
end tell

That's all AppleScript except the "this.deletePages(0);" bit. That's the JavaScript I'm firing at the frontmost document. Where did I get the JavaScript from? By reading the JavaScript for Acrobat API Reference which you can find here:

http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf

One thing to watch out for is that JavaScript (like many languages except AppleScript) numbers things starting with 0, rather than 1. So if I want to delete the first page then I need "this.deletePages(0);". If I wanted to delete the second page then it's "this.deletePages(1);" and so on.

To see if the rest of your goals are achievable, I recommend you read the JavaScript reference above, or at least the appropriate parts! ;-)

Good luck.



 
We're covered in work lately and I had no time to read anything : (
I know I'm wasting lots of time the way I'm working now. So as soon as I have a bit of time I'll see if I can understand the pdf you linked me. Thanks for all help!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.