Very slow AppleScript
Very slow AppleScript
- Subject: Very slow AppleScript
- From: "emile.a.schwarz" <email@hidden>
- Date: Fri, 01 Mar 2013 09:13:48 +0100 (CET)
Hi all,
Hardware / Software: MacBook Pro 2011-11, Mountain Lion
The code below takes tons of time to just get a reference of an item from the user selected folder.
If I remove or comment the line of code from the repeat block, the code execution takes nearly no time.
With this line (just below), it takes 7 seconds to only store a reference to one item from the choosed folder. No matter if I use a numéric value or like I do in the original script a variable inc in the repeat loop.
set ItemToChange to item 1 of SelectedFldr
The original code use a variable instead of 1 (LoopIdx) who is incremented just before end repeat. I removed a long If .../... Else block to be sure it was that who takes tons of time to be executed to discover the real line who takes tons of times (depends of the number of real files to check on disk.
Here's the script:
tell application "Finder"
# Keyboard shortcut
set fw to front window # always use the front window (otherwise choose one…)
# Create local variables
set SelectedFldr to alias # Target folder container
set TFItemCnt to 0 # Store the number of items in the target folder
set ItemToChange to alias # Local reference to the item to work with
# set LoopIdx to 1 # Repeat loop indice
# get a reference of the front window
set fwFldr to target of fw
# ask the user to choose a folder (displays the front window in the dialog)
set SelectedFldr to choose folder default location (fwFldr as alias)
# get the number of items in the target folder
set TFItemCnt to number of item in (SelectedFldr as reference)
repeat 10 times
set ItemToChange to item 1 of SelectedFldr
# I removed the working code from here
end repeat
# This takes 7 second
# go back here
tell me to activate
end tell
Is it only my Mt Lion, my 2011-11 MacBook Pro 15", the Captain and the Kids or is it slow for you too ?
Also, is it a way to do that faster ?
TIA,
Emile
PS: I removed the code who check the file ID and set the name extension accordingly (a.k.a. replace "cbz" with "zip" if I found "PK" in the start of the file; same for "rar" instead of "cbr" if I found "Rar", and so on *). Surprisingly enough, this takes nearly no time.
* some people are queer than me: the change the file name extension from rar to cbz for unknow reasons ! And UnRarX complains !
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden