|Jun 22, 2013, 11:43 PM||#1|
Greater than or equal to problem.
I'm building a script for Final Cut Pro (7) this is a small part of the entire script and I am having some difficulties getting this to work. So, the objective is to get a number from the user, then to have the number escalate as it repeats. I also need to make this number "Paste" in. However I cannot use the cliboard functions at all because they will be in use in a different part of the script.
What this part was designed to do, (but doesn't do all the time ) is take the number submitted by the user, and break it down by digit and spit it back out in the form of a variable key code. Another part of the script would do the escalation of the number. But what I really need is to find out why the greater than or equal to/ less than or equal to aren't correctly segmentig the numbers, so the script doesn't try to do the input number more than once.
set start_value to text returned of (display dialog "Start number?: " default answer "") as number if start_value is greater than or equal to 0 then if start_value is less than or equal to 9 then set start_value to start_value as string set start_value01 to 0 set start_value02 to 0 set start_value03 to the first item of start_value as number end if end if if start_value is greater than or equal to 10 then if start_value is less than or equal to 99 then set start_value to start_value as string set start_value01 to 0 set start_value02 to the first item of start_value as number set start_value03 to the second item of start_value as number end if end if if start_value is greater than or equal to 100 then if start_value is less than or equal to 999 then set start_value to start_value as string set start_value01 to the first item of start_value as number set start_value02 to the second item of start_value as number set start_value03 to the third item of start_value as number end if end if if start_value01 is 1 then set O1 to 18 if start_value01 is 2 then set O1 to 19 if start_value01 is 3 then set O1 to 20 if start_value01 is 4 then set O1 to 21 if start_value01 is 5 then set O1 to 23 if start_value01 is 6 then set O1 to 22 if start_value01 is 7 then set O1 to 26 if start_value01 is 8 then set O1 to 28 if start_value01 is 9 then set O1 to 25 if start_value01 is 0 then set O1 to 29 if start_value02 is 1 then set O2 to 18 if start_value02 is 2 then set O2 to 19 if start_value02 is 3 then set O2 to 20 if start_value02 is 4 then set O2 to 21 if start_value02 is 5 then set O2 to 23 if start_value02 is 6 then set O2 to 22 if start_value02 is 7 then set O2 to 26 if start_value02 is 8 then set O2 to 28 if start_value02 is 9 then set O2 to 25 if start_value02 is 0 then set O2 to 29 if start_value03 is 1 then set O3 to 18 if start_value03 is 2 then set O3 to 19 if start_value03 is 3 then set O3 to 20 if start_value03 is 4 then set O3 to 21 if start_value03 is 5 then set O3 to 23 if start_value03 is 6 then set O3 to 22 if start_value03 is 7 then set O3 to 26 if start_value03 is 8 then set O3 to 28 if start_value03 is 9 then set O3 to 25 if start_value03 is 0 then set O3 to 29 tell application "TextEdit" activate tell application "System Events" tell process "TextEdit" key code O1 delay 0.1 key code O2 delay 0.1 key code O3 end tell end tell end tell
Text Edit being my test dummy for this part of the operation. I am on 10.8, a couple others will be on 10.7.
Thanks for any help on this!
Last edited by dejo; Jun 23, 2013 at 12:46 AM. Reason: please use [code] tags.
|Jun 23, 2013, 12:35 AM||#2|
The problem is that if you have a line such as:
if start_value is greater than or equal to 100 thenwhere start_value is a string, then AppleScript will perform a text comparison - ie is start_value after, alphabetically, "100". This is true for values such as "5" or "43".
To solve this, just convert start_value to a number first, eg:
if (start_value as number) is greater than or equal to 100 thenAlternatively, change your code so that it doesn't convert start_value to a string, or use 'else if' statements rather than 'if' so that it doesn't check for multiple cases where only one should be possible anyway.
However, your code can be greatly simplified, which avoids the problem altogether. The following is functionally equivalent to your original code (with a little extra code for error checking):
set start_value to text returned of (display dialog "Start number?: " default answer "") try set start_value to start_value as integer if (start_value < 0 or start_value > 999) then -- not in the required range - do something else set start_value03 to start_value mod 10 set start_value02 to start_value mod 100 div 10 set start_value01 to start_value mod 1000 div 100 tell application "TextEdit" activate tell application "System Events" tell process "TextEdit" keystroke (start_value01 as string) delay 0.1 keystroke (start_value02 as string) delay 0.1 keystroke (start_value03 as string) end tell end tell end tell -- do whatever else you want to do end if on error e -- not a number (or some other error) - do something end try
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|iPhone: Spoof 7.0.6 or greater on 5s running 7.0.4?||Chalked||Jailbreaks and iOS Hacks||5||Mar 18, 2014 02:32 PM|
|iPad Mini: So no Mini greater than 16GB for xmas?||walmartmartyr||iPad||7||Oct 30, 2013 11:57 AM|
All times are GMT -5. The time now is 01:43 PM.