handlers - Applescript: Getting a list of numbered folders from a shell script and identifying the highest value -


i have 2 different handlers, 1 gets names (which numbers "1.0" , "1.1") of folders within folder, converts applescript list. passes list handler, evaluates list , supposedly identifies highest number (i got http://www.macosxautomation.com/applescript/sbrt/sbrt-03.html ).

on set_values(project_path) shell script "ls " & project_path words of result set allvalues (result) return allvalues end set_values 

then turn result variable next handler:

set values_list result 

and handler highest number list, courtesy of macosxautomation:

on highnum(values_list) set high_amount "" repeat 1 count of values_list     set this_item item of values_list     set item_class class of this_item     if item_class in {integer, real}         if high_amount ""             set high_amount this_item         else if this_item greater high_amount             set high_amount item of values_list         end if     else if item_class list         set high_value highnum(this_item)         if the high_value greater high_amount ¬             set high_amount high_value     end if end repeat return high_amount end highnum 

the problem second handler ever gives off null response, , can't figure out why. appreciated.

the point of application simplify creation of other applications, allowing creation of new 'projects', importing existing apps new 'project' , allow editing of 'project' ease. in event choose edit project, can choose "minor update" (effectively adding '0.0.1' latest version) or number of other options have finished. multi-decimal addition can solve using text item delimiters, not sure how obtain multi-decimal number highnum() handler, critical part of process

the highnum() handler compares real , integer values shell script returns string values.

applescript has built-in option compare numeric strings.

edit: values contain @ least 1 dot , not contain letter considered.

on highnum(values_list)     set high_amount "0.0"     considering numeric strings         repeat avalue in values_list             set {tid, text item delimiters} {text item delimiters, "."}             set avalueitems text items of avalue             if (count avalueitems) > 1                 set text item delimiters ""                 try                     avalueitems text integer                     if avalue > high_amount set high_amount contents of avalue                 end try             end if             set text item delimiters tid         end repeat     end considering     return high_amount end highnum 

this simpler version of set_values() handler

on set_values(project_path)     return paragraphs of (do shell script "ls " & project_path) end set_values 

to add version strings use handler, considers strings different "decimal places".

set newversionstring addversionstrings("1.1.1", "2.0") --> 3.1.1  on addversionstrings(string1, string2)     set {tid, text item delimiters} {text item delimiters, "."}     set textitems1 text items of string1     set textitems2 text items of string2     if (count textitems1) < (count textitems2)         set mincount count textitems1         set _sum textitems2         set _add textitems1     else         set mincount count textitems2         set _sum textitems1         set _add textitems2     end if     repeat 1 mincount         set item of _sum (get (item of _sum integer) + (item of _add integer)) text     end repeat     set theresult _sum text     set text item delimiters tid     return theresult end addversionstrings 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -