Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript - progressive loops get slower. Solutions?

Hi all,


I made a terrible Automator script and because it performed so badly (thanks to 'Watch Me Do') I eventually replaced every section with an Applescript action I wrote myself. My Applescript knowledge is limited so my scripts are rudimentary - but they work. My issue is that as it processes, each successive loop gets exponentially slower!


Here's what I'm tying to do:

We have 47 invoices with hundreds of lines of products in most of them. I have a list of product codes we should not have been charged and I need to ascertain if those codes appear on these invoices.


Here's my planned method:

  • Extract the entire (text) contents of each PDF invoice and (prefaced by the PDF filename so I can identify the guilty invoice) paste it into TextEdit for 'massaging' into spreadsheet-friendly formatting.
  • Copy and paste massaged content into Numbers and use the 'COUNTIF' function (or other suitable argument) to highlight instances of being charged


Here's my Automator script: https://www.dropbox.com/s/8j0suedsrq852b9/Use%20name%20of%20this%20file%20in%20s cript.workflow.zip?dl=0


I know there are better more efficient scripts that will perform the same task better, but I'm keen to learn two things:

  1. Why does it get exponentially slower and how to prevent this for future scripts
  2. A more efficient way of getting this done. (Using Finder to search file contents of the enclosing folder doesn't work because the way the PDF's are constructed/formatted)

Any help or input is greatly appreciated.

Thanks!

Jeremy

MacBook Pro (Retina, Mid 2012), OS X Yosemite (10.10.5)

Posted on Feb 11, 2016 7:25 PM

Reply
3 replies

Feb 12, 2016 8:29 AM in response to MrHuman

Hi Jeremy,


I clicked your link and had a look at the script in Automator. This is what I found:


on run {input, parameters}


tell application "System Events" to set myinitials to do shell script "rawName=" & quoted form of (get name of (path to me)) & "; printf '%s' \"${rawName%.*}\""


set getDate to do shell script "date +%y%m%d"

set theDate to (getDate as string)


tell application "System Events"


set the clipboard tomyinitials & theDate


keystrokereturn


keystroke (key code 123)


keystroke (key code 9 usingcommand down)

end tell



return input

end run


There's no loop in the script, and also the question doesn't seem to relate to Numbers. Perhaps you could post your problem in the Mac OS X Technologies section, providing more specifics.


SG

Feb 12, 2016 4:54 PM in response to SGIII

Hi SG,


Oops! I uploaded the wrong file. If you're still keen to look at it I've put it up again, here: https://www.dropbox.com/s/wx90ryzle9mofp3/Extract%20VSS%20PDF%20Invoice%20Conten ts.workflow.zip?dl=0


The number of loops has been reduced to only doing 3 cycles at a time because the slowdown was occurring after 4 or 6 cycles (if I recall correctly).


I wasn't sure what category to submit this into (I've read other people's concerns about this very thing). If you think it will get more attention in Mac OS X Technologies I'll repost it in there. Thanks SG!

Feb 12, 2016 5:04 PM in response to MrHuman

Hi,


Since this is not a Numbers question I think you will get more attention in Mac OS X Technologies.


Perhaps start a new thread there stating clearly what you are trying to do, and giving a specific example of what an invoice looks like and what you want to search for in the invoice.


It strikes me that this may be better suited to a "standalone" AppleScript rather than various 'Run AppleScript' actions in Automator, but the scripting gurus there will have a better idea.


SG

Applescript - progressive loops get slower. Solutions?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.