Hi there!
So, I made my very first ever script in order to create several thousand QR Codes for my boss. The script works (most of the time) but the problem I’m having is the speed. The script takes 4 seconds to create one code, which is fine except for the fact that we will need to create 75,000 codes at one time. This comes out to a total of 83 hours to create them all! I have a few delays in my script and I have tried taking them out and shortening them but any more alterationds causes the script to not work correctly.
I’m sure that the script will look super newbish to pros like you guys but any suggestions would be grand.
The script:
How it works:
The script relays on a couple factors. The “command q” shortcut triggers another script that makes the QR code, which I did not write:
My script works with this one using a text file that is placed in a folder with the script linked to it. I hope this is making sense, I’m sure it seems backwards and weird. To make a long story short, I need to somehow make this work faster and I am willing to rework the entire thing or go with a new idea entirely. Thanks in advance!
-Erin
So, I made my very first ever script in order to create several thousand QR Codes for my boss. The script works (most of the time) but the problem I’m having is the speed. The script takes 4 seconds to create one code, which is fine except for the fact that we will need to create 75,000 codes at one time. This comes out to a total of 83 hours to create them all! I have a few delays in my script and I have tried taking them out and shortening them but any more alterationds causes the script to not work correctly.
The script:
Code:
on adding folder items to this_folder after receiving these_items
repeat with an_item in these_items
tell application "TextEdit"
activate
open an_item
tell application "TextEdit"
activate
end tell
tell application "System Events"
keystroke "a" using command down
end tell
tell application "System Events"
keystroke "c" using command down
end tell
tell application "System Events"
keystroke "w" using command down
end tell
delay 0.25
tell application "System Events"
keystroke "q" using command down
end tell
delay 0.25
tell application "System Events"
keystroke "v" using command down
end tell
tell application "System Events" to keystroke return
delay 0.25
tell application "Preview"
activate
end tell
delay 0.25
tell application "System Events"
keystroke "s" using command down
end tell
delay 0.25
tell application "Preview"
activate
end tell
delay 0.75
tell application "System Events" to keystroke return
delay 0.5
tell application "System Events" to keystroke return
delay 0.25
tell application "System Events"
keystroke "w" using command down
delay 0.25
end tell
end tell
end repeat
end adding folder items to
How it works:
The script relays on a couple factors. The “command q” shortcut triggers another script that makes the QR code, which I did not write:
Code:
set the theRes to "300"
display dialog "URL?" default answer "http://www.google.com"
set the theURL to the text returned of the result
set input to "http://chart.apis.google.com/chart?cht=qr&chs=" & theRes & "x" & theRes & "&chl=" & theURL
set input to quoted form of input
set temp_file to (path to temporary items)
set temp_name to do shell script "uuidgen"
set temp_file to (POSIX path of temp_file) & temp_name
set q_temp_file to quoted form of temp_file
set cmd to "curl -o " & q_temp_file & " " & input
do shell script cmd
set x to alias (POSIX file temp_file)
tell application "Finder" to open x
My script works with this one using a text file that is placed in a folder with the script linked to it. I hope this is making sense, I’m sure it seems backwards and weird. To make a long story short, I need to somehow make this work faster and I am willing to rework the entire thing or go with a new idea entirely. Thanks in advance!
-Erin
Last edited by a moderator: