(*

Reroute.

Application

Drag documents onto the applications icon, and you can set the folder it routes to, based on file extension. This choice will be remembered, and auto routes the next time it set the file extention.

*)

property dotext : { }

property dotextloc : { }

property ver : "110426"

on open thefiles

tell application "Finder"

repeat with i from 1 to length of thefiles

--if last character of (item i of thefiles as string) ≠ ":" then

set x to name of item i of thefiles

if x contains "." then

set tempfile to last item of ( my stringtolist ( x, "." ) )

--display dialog tempfile as string

if dotext does not contain tempfile then

set end of dotextloc to choose folder with prompt "Please choose the folder you want \" " & tempfile & "'s \" saved"

set end of dotext to tempfile

end if

repeat with i2 from 1 to length of dotext

if item i2 of dotext = tempfile then

move ( item i of thefiles ) to ( item i2 of dotextloc ) with replacing

end if

end repeat

else

display dialog "The file " & x & " does not contains a .ext, so it will be ignored." with title ver

end if

--end if

end repeat

end tell

end open

on run { }

my _editor ( )

end run

on _editor ( )

set breturn to button returned of ( display dialog "Fix a ReRoute" buttons { "Cancel" , "Panic!..." , "Fix One..." } default button "Fix One..." with title ver )

if breturn = "Panic!..." then

set breturn2 to button returned of ( display dialog "This will delete all bindings to files?" buttons { "Cancel" , "Delete All" } default button 1 with title ver )

if breturn2 = "Delete All" then

set dotext to { }

set dotextloc to { }

end if

end if

if breturn = "Fix One..." then

if length of dotext ≠ 0 then

set x to 0

set dotextTOFIX to ( choose from list dotext with title ver )

repeat with i3 from 1 to length of dotext

set x to x + 1

if ( item i3 of dotext as string ) = ( dotextTOFIX as string ) then

exit repeat

end if

end repeat

if x ≠ 0 then

set tfolder to ( choose folder with prompt "Current Path for \" ." & ( item i3 of dotext as string ) & " \"

" & item x of dotextloc )

set item x of dotextloc to tfolder

end if

else

display dialog "You must add a .ext before you can edit them!"

end if

end if

end _editor

--to get a string such as "this is a test" into a list of strings, yo do this: set x to stringtolist(thestring, " ")

--so thestring is obviosly "this is a test" and the delimter is " " so then youd get something returned from that looking like {"This", "is", "a", "test"} so then you could do set y to item 2 of x, then y would equal to "is"

on stringtolist ( theString, delim )

set oldelim to AppleScript ' s text item delimiters

set AppleScript ' s text item delimiters to delim

set dlist to ( every text item of theString )

set AppleScript ' s text item delimiters to oldelim

return dlist

end stringtolist

on ListToString ( theList, delim )

set oldelim to AppleScript ' s text item delimiters

set AppleScript ' s text item delimiters to delim

set alist to theList as string

set AppleScript ' s text item delimiters to oldelim

return alist

end ListToString

----

(*

FolderRename

Application

Drag a file onto the application, and it will create a folder with the same name, and place the file into this new folder.

*)

on open theDropped

repeat with oneDrop in theDropped

set posixfilepath to ( the POSIX path of oneDrop )

set posixfilepathLIST to emptylist ( stringtolist ( posixfilepath, "/" ) )

if ( last item of posixfilepathLIST ) contains ".avi" or ( last item of posixfilepathLIST ) contains ".mkv" or ( last item of posixfilepathLIST ) contains ".mov" or ( kind of ( info for posixfilepath ) ≠ "Folder" ) then

--set thename to item 1 of stringtolist(last item of posixfilepathLIST, ".")

set thename to ( ListToString ( ( reverse of ( rest of ( reverse of ( stringtolist ( last item of posixfilepathLIST, "." ) ) ) ) ) , "." ) )

set posixfilepathLISTCLEANED to reverse of ( rest of ( reverse of posixfilepathLIST ) )

set posixfilepathSTRINGCLEANED to ListToString ( posixfilepathLISTCLEANED, "/" )

do shell script "mkdir \" /" & posixfilepathSTRINGCLEANED & "/" & thename & "/ \" "

--display dialog quoted form of ("rm " & posixfilepath & posixfilepathSTRINGCLEANED & thename)

do shell script "mv \" " & posixfilepath & " \" \" " & "/" & posixfilepathSTRINGCLEANED & "/" & thename & "/ \" "

end if

end repeat

end open

on emptylist ( klist )

set nlist to { }

set dataLength to length of klist

repeat with i from 1 to dataLength

if item i of klist is not "" then

set end of nlist to ( item i of klist )

end if

end repeat

return nlist

end emptylist

on ListToString ( theList, delim )

set oldelim to AppleScript ' s text item delimiters

set AppleScript ' s text item delimiters to delim

set alist to theList as string

set AppleScript ' s text item delimiters to oldelim

return alist

end ListToString

on stringtolist ( theString, delim )

set oldelim to AppleScript ' s text item delimiters

set AppleScript ' s text item delimiters to delim

set dlist to ( every text item of theString )

set AppleScript ' s text item delimiters to oldelim

return dlist

end stringtolist

----

(*

iEnter

Application

Writes your work schedule to iCal very easily.

*)

--Important Note: All times must be entered in military time, so 3:00PM is "15"

-- Added support for short hours (different length of shift) to enter these, you would do "13-1" This would start the shift at 1pm, and with shift_length being 9 hours, would reduce this by 1 hour, so a 1-9 would be scheduled, instead of a 1-10

property shift_length : "9" --Number of hours shift last, defaults to 9, 8 hours + 1 hour lunch

property shift_start : "8" --Default shift start time, good thing to set if you always start at a certain time. Once you enter another entry in the field, it will default to that time.

property calendar_name : "" --The Calendar you want to save it to in iCal

property the_location : "" --Default "Location" field

property the_location_temp : ""

property vernum : " iEnter 2.2d" --Version Tracking information --if there is a "d" its dev version which has comments

property Event_name : "Work" --iCal event name

property iEnterOutPutFile : "iEnterDataFile.txt"

property ChangeEndTimeOffset : 0

(*

Version History:

1.0

This version works, but needs some shiny things

1.2

Added Icon when adding schedule

1.3

Added Dummy logic to entered time.

-If user enters anything aside from 1-24, it will present a message, and only option is to quit.

1.5

Aded Logic to ask name of location and calendar name.

1.5.1

Added Variable so you can change what the event name is.

1.5.2

Pulled list of available calendars from ical, so one less thing a user can screw up.

Changed bounds checking to allow entry as 8.5 for a 8:30 start, etc

1.5.5

Added config file to save data, so when users change versions of iEnter, they dont need to resetup everything

Added Option to allow you to enter number of hours in workday.

Showed Calendar that is being saved to in data entry dialog

1.5.6

Showing event name and location in data entry dialog

1.6

Fixed issues with application not opening iCal (Calendar)

Changed all references to "iCal" or "Calendar" to…

tell application id "com.apple.iCal"

Added support for short hours (different length of shift) to enter these, you would do "13-1" This would start the shift at 1pm, and with shift_length being 9 hours, would reduce this by 1 hour, so a 1-9 would be scheduled, instead of a 1-10

2.0

Awesome new feature, now checks to see what your last scheduled day was, and then asks you about the next day, no longer have to click "Day off" until you catch up.

2.0.1

Marks the event_name with a "•" in the beginning if the offset was used (ex 13-2 in the time line)

d

All future version will have a "d" on it, as the script is now readable in applescript editor and i have included comments

2.0.1.1

Removed the cancel button 1 option to the main window, so we could fire off a routine when the script exits

2.0.3

Finally fixed issue with getting the correct day when finding the last appointment that matches Event_name

2.1

If you include a @ anywhere in the entered text string, you can change the location for that one day, it will prompt you.

2.2

We use iCal icon, so it runs more universally

*)

on run { }

--checks to see if ical is running, if it isnt, then it launches it

tell application "System Events"

if ( count of ( every process whose bundle identifier is "com.apple.iCal" ) ) = 0 then

tell application id "com.apple.iCal" to activate -- Used bundle instead of application as iCal is now Calendaar. It "may" work that way, but i can see the user clicking on the app, and getting the dreaded applescript "Which Application are you talking about" Bad experience i guess

delay 5

end if

end tell

--

--checks exists on a file on the filesystem. if it finds the file, the script assumes its been "setup" and skips running setup

tell application "Finder"

if exists file ( ( path to documents folder ) & iEnterOutPutFile as string ) then

set RunSetup to false

else

set RunSetup to true

end if

end tell

--

-- THIS IS setup

if RunSetup = true then

--If iCal is running, pull a list of calendars

tell application id "com.apple.iCal" to set theCalendars to name of every calendar

--this used to ask the user which calendar, and they would type it in. i used an error block in case the dumb user put in something like "peanut butter". This will now just list the calendars, and the user chooses one.

try

set calendar_name to item 1 of ( choose from list theCalendars with prompt "Choose the name of the Calendar you would like to Sync to: " OK button name "Continue" cancel button name "Quit" )

on error

--dumped us out on error

return false

end try

--

-- Ask the user for the correct data

set the_location to text returned of ( display dialog "Enter the name of the Location" default answer the_location )

set Event_name to text returned of ( display dialog "Enter the name of the Event" default answer Event_name )

set shift_length to text returned of ( display dialog "How long are the shifts?" default answer shift_length )

--

--this will actually write the data to the file in the filesystem

my save_data ( )

--

--Ahh yess, this, well, could be done I suppose but havent yet, maybe in 2.0 ?

--set appwalkthrough to button returned of (display dialog "Would you like an tutorial on how to use this application?" buttons {"No", "Yes"} default button "Yes")

--if appwalkthrough is "Yes" then

--display dialog "When the app launches, it will start on todays date. If you've previously used the app it may just bump you to the next day where you dont have an event with the name as specified listed. -- run example of there data, and maybe a "simulator"

--end if

end if

--This will fire off a subroutine to actually read the data from the text file on the filesystem. not much error checking here, but any error would just exit the app, so its psuedo safe

my read_data ( )

--

--new block, starts you where you havent schduled a shift start yet

tell application id "com.apple.iCal"

tell calendar calendar_name

-- asks ical to look for your scheduled event in the future, and return a list, VERY SLOW< SPEED ME UP

set theEventList to every event whose summary contains Event_name and start date > ( current date )

end tell

-- pulls current date

set thetest to current date

--

--searches list of events "theEventList", and finds the oldest one. I know "every" is suppose to return them in order, but it doesnt, otherwise i could pull a last item of theEventList and call it a day

repeat with i from 1 to length of theEventList

if ( start date of item i of theEventList ) > thetest then

set thetest to ( start date of item i of theEventList )

end if

end repeat

--thetest will end up as the oldest date in the list, so we use that, this compares thetest to now, which returns a second offset, we divide that by number of seconds in the day. this is actually a bug as sometimes when the user is prompted to enter his next scheduled day, it may be off by 1, im sure there is an easy way to fix that either rounding of user "days" instead of 86400 but shrug --fixed issue i was using "div"operator which chops off tbe decimal, so it was returning 2.917237 but div returns 2, now i just straight divide and round to the nearest whole number--still doesnt work all the time

-- sets the time to midnight, as we waant to compare days, which gets complicated when comparing 2 different times

set time of thetest to 0

set thetest2 to current date

set time of thetest2 to 0

set schduledOffset to round ( thetest - ( thetest2 ) ) / 86400

end tell

--

--Will front this application once it prompts the user

tell me to activate

--

--loop starts interaction with user about the next scheduled event, in some case, this may be the first time the user sees us =)

repeat with i from ( schduledOffset + 1 ) to 60

set ChangeEndTimeOffset to 0

set userdata to ( display dialog "Enter Start Time for:

" & date string of ( ( current date ) + i * days ) & "

Calendar: " & calendar_name & "

Event: " & Event_name & " @ " & the_location default answer shift_start buttons { "Quit" , "Day Off" , "Next Day" } default button 3 with title vernum with icon path to resource "App-empty.icns" in bundle application id "com.apple.iCal" )

--if quit is chosen, this fires, which will exit the app

if button returned of userdata is "Quit" then

exit repeat

end if

--

if ( text returned of userdata as string ) contains "@" then

set text returned of userdata to listtostring ( my stringtolist ( ( text returned of userdata as string ) , "@" ) , "" )

set the_location_temp to text returned of ( display dialog "What is this events location?" default answer the_location )

end if

--new block, adds short shift support

--looks at the string the user enters, for "-" charecter, if it finds one, it spilts the string using stringtolist which returns a list of strings using "-" as the delimter

--grabs the first item, and pushes it to user returned data, as you can see this wasnt added right away, but this seems like a solution. the second item is our offset we need

if ( text returned of userdata as string ) contains "-" then

set ChangeEndTime to stringtolist ( ( text returned of userdata ) , "-" )

set text returned of userdata to ( item 1 of ChangeEndTime )

set ChangeEndTimeOffset to ( item 2 of ChangeEndTime )

end if

try

--Makes sure the user did not enter alpha characters . This coercern will fail, and trigger the on error block which alerts the user, and exits repeat, which in turn quits the app

set checkdata to ( text returned of userdata as number )

--if an error occures we need to error the repeat to force the app to close

on error errnum

display dialog "All times must be entered in military time, so 3:00PM is \" 15 \"

" & errnum with icon stop buttons "Quit" default button 1

exit repeat

end try

--if we get here, no error occured and we move on

--so we know the data recieved as at least valid. next block will also check to make sure the numbers are under 24

--all this is done to make sure the data that gets recorded in ical is as accurate as possible, so we run this bounds checks to make sure no error occurs

if ( text returned of userdata as number ) ≤ 24 then

if button returned of userdata is "Next Day" then

set shift_start to text returned of userdata

my create_event ( date string of ( ( current date ) + i * days ) as string , text returned of userdata )

end if

if button returned of userdata is "Day Off" then --a bit redundent i am sure, just wanted to add it in case i wanted to fire something at some point

end if

else

display dialog "Only numbers 0-24 are valid" with icon stop buttons "Quit" default button 1

exit repeat

end if

end repeat

end run

-- subroutine for …creating events

--So in theory this wouldn't be called if we didnt have all the data

on create_event ( theDate, startime )

set adjusteddata to ( ( date ( theDate as string ) ) + startime * hours )

--check to see if the offset option is used (using a minus in text field) and adds an "*" to the beginning of the Event_name. again, kind of lazy but i didnt want to break Event_name value

tell application id "com.apple.iCal"

tell calendar calendar_name

--if ChangeEndTimeOffset wasnt changed, it does a "standard" calendar write.. oh yes, this is "middle" and the point to all of this =)

-- when testing the script, i will often just comment out these 2 lines to test.

if the_location_temp ≠ "" then

set the_location_hold to the_location

set the_location to the_location_temp

end if

if ChangeEndTimeOffset is 0 then

make new event at end with properties { summary:Event_name, location:the_location, start date:adjusteddata, end date:adjusteddata + shift_length * hours - ChangeEndTimeOffset * hours }

else

make new event at end with properties { summary: "•" & Event_name, location:the_location, start date:adjusteddata, end date:adjusteddata + shift_length * hours - ChangeEndTimeOffset * hours }

end if

if the_location_temp ≠ "" then

set the_location to the_location_hold

set the_location_temp to ""

end if

end tell

end tell

end create_event

--takes the variable data and saves it to the filesystem

on save_data ( )

set ref_num to open for access file ( ( path to documents folder ) & iEnterOutPutFile as string ) with write permission

set eof of ref_num to 0

write calendar_name & return & the_location & return & Event_name & return & shift_length to ref_num

close access ref_num

end save_data

--takes the the data in the filesystem, and writes to to a variable

on read_data ( )

set ienterdatapath to ( ( path to documents folder ) & iEnterOutPutFile as string )

set ref_num to open for access file ienterdatapath with write permission

set ienterdata to read ref_num

close access ref_num

set { calendar_name, the_location, Event_name, shift_length } to stringtolist ( ienterdata, return )

end read_data

--takes a string of data like "hello, my name is Mike" and converts it into {"hello,","my","name","is","Mike"} so that you can specify first item, second item or walk down a list searching, listtostring() does the opposite. listtostring is not used in this script, but I have included that code below, as these 2 should always be with each other.

on stringtolist ( theString, delim )

set oldelim to AppleScript ' s text item delimiters

set AppleScript ' s text item delimiters to delim

set dlist to ( every text item of theString )

set AppleScript ' s text item delimiters to oldelim

return dlist

end stringtolist

on listtostring ( theList, delim )

set oldelim to AppleScript ' s text item delimiters

set AppleScript ' s text item delimiters to delim

set alist to theList as string

set AppleScript ' s text item delimiters to oldelim

return alist

end listtostring

----

(*

Folder Action

Useful for Plex installs.

When a file is added to a folder, say a TV Show folder, that is flat (no season folders) the script will look at all the files in the directory, and remove them if they are older then 2 weeks, you can change the duration in code.

I use this for TV daily tv shows, like late night shows. SickRage can change the modification date to the air date, so this makes this script more effective.

*)

-- 2.428571428571 * weeks is basically 15 days

on adding folder items to this_folder after receiving these_items

tell application "Finder"

set the_files to every file of this_folder

repeat with i from 1 to length of the_files

if ( ( modification date of ( get info for ( item i of the_files as alias ) ) ) + 2.428571428571 * weeks ) < ( current date ) then

--display dialog "1 " & item i of the_files

--set label index of (item i of the_files) to 2

delete ( item i of the_files )

else

--display dialog "2 " & item i of the_files

end if

end repeat

end tell

end adding folder items to

----

--ISO8601toUTCdateObject will take a string that looks like "2016-04-10T09:13:32.284-05:00" and create a date object with these values. returned value is UTC/GMT

--ISO8601toUTCdateObject will take aline that looks like "2016-04-10T09:13:32.284-05:00" and create a date object with these values. returned value is UTC/GMT

on ISO8601toUTCdateObject ( the_time )

set time_parsed to my stringtolist ( "IS08601" , the_time, { "-" , "T" , ":" , "." , "-" } )

set date_object to current date

set hours of date_object to ( ( item 4 of time_parsed ) + ( item 8 of time_parsed ) )

set minutes of date_object to item 5 of time_parsed

set seconds of date_object to item 6 of time_parsed

set year of date_object to item 1 of time_parsed

set month of date_object to item 2 of time_parsed

set day of date_object to item 3 of time_parsed

return date_object

end ISO8601toUTCdateObject

display dialog my ISO8601todateObject ( "2016-04-10T09:24:32.284-05:00" )

on stringtolist ( the_caller, theString, delim )

log "stringtolist: " & the_caller

--display dialog theString & return & delim as text

set oldelim to AppleScript ' s text item delimiters

set AppleScript ' s text item delimiters to delim

set dlist to ( every text item of theString )

set AppleScript ' s text item delimiters to oldelim

--if AppleScript's text item delimiters ≠ {""} then

-- display dialog AppleScript's text item delimiters

--end if

return dlist

end stringtolist

Other handler helpers.

on indent_text ( ident_item, ident_times )

set ident_temp to { }

repeat with i from 1 to ident_times

set end of ident_temp to ident_item

end repeat

return my listtostring ( ident_temp, "" )

end indent_text

on string_contains ( sc_list, sc_item )

log "string_contains: " & sc_item & " !!! " & my listtostring ( sc_list, "/" )

repeat with i from 1 to length of sc_list

if sc_item contains item i of sc_list then

return { i, item i of sc_list }

exit repeat

end if

end repeat

return { 0 , 0 }

end string_contains

on flatten_list ( alists )

set clean_result to { }

repeat with i from 1 to length of alists

repeat with j from 1 to length of item i of alists

set end of clean_result to item j of item i of alists

end repeat

end repeat

return clean_result

end flatten_list

on list_position ( this_item, this_list, is_strict )

-- log "list_post: " & this_item

--log "list_post2: " & my listtostring(this_list, " ")

if this_item ≠ false then

repeat with i from 1 to the length of this_list

if is_strict = false then

if ( item i of this_list as text ) contains this_item then

log "list_post2: ~" & i

return i

end if

else

if ( item i of this_list as text ) is ( this_item as text ) then

log "list_post2: " & i

return i

end if

end if

end repeat

end if

log "list_post2: 0"

return 0

end list_position

on logtime2datetime ( date_object )

--(*10, 22, 16, 03, 25, 39, 545*)

if date_object ≠ "" then

set epoch_time to current date

set time_parsed to my stringtolist ( "logtime2datetime" , date_object, { "." , " " , ":" } )

set hours of epoch_time to item 4 of time_parsed

set minutes of epoch_time to item 5 of time_parsed

set seconds of epoch_time to item 6 of time_parsed

set year of epoch_time to 2000 + ( item 3 of time_parsed )

set month of epoch_time to item 1 of time_parsed

set day of epoch_time to item 2 of time_parsed

return epoch_time

else

return missing value

end if

end logtime2datetime

on datetime2epoch ( the_date_object )

set epoch_time to current date

set hours of epoch_time to 0

set minutes of epoch_time to 0

set seconds of epoch_time to 0

set year of epoch_time to "1970"

set month of epoch_time to "1"

set day of epoch_time to "1"

return my getTfromN ( the_date_object - epoch_time )

end datetime2epoch

on epoch2datetime ( epochseconds )

set epoch_time to current date

try

set unix_time to ( characters 1 through 10 of epochseconds ) as text

on error

set unix_time to epochseconds

end try

set hours of epoch_time to 0

set minutes of epoch_time to 0

set seconds of epoch_time to 0

set year of epoch_time to "1970"

set month of epoch_time to "1"

set day of epoch_time to "1"

log "epoch_time: " & epoch_time

--epoch_time is now current unix epoch time as a date object

set epochOFFSET to ( epoch_time + ( unix_time as number ) + ( time to GMT ) )

log "epochOFFSET: " & epochOFFSET

return epochOFFSET

end epoch2datetime

on ISO8601todateObject ( the_caller, the_time )

log " on ISO8601: " & the_caller & ":" & the_time

if the_time is not in { "0" , 0 , missing value , "" } then

--if the_time ≠ 0 or the_time ≠ missing value then

-- if the_time ≠ "" then

--converts ISO8601 date string, and turns it into a date object

set time_parsed to my stringtolist ( "IS08601" , the_time, { "-" , "T" , ":" , "." , "+" , "Z" , " " } )

set date_object to current date

set hours of date_object to item 4 of time_parsed

set minutes of date_object to item 5 of time_parsed

set seconds of date_object to item 6 of time_parsed

set year of date_object to item 1 of time_parsed

set month of date_object to item 2 of time_parsed

set day of date_object to item 3 of time_parsed

return date_object

else

return ""

-- end if

end if

end ISO8601todateObject

on filter_lines ( the_lines, the_delimiter )

set parsed_the_lines to ""

set cleaned_the_lines to { }

set result_words_list to { }

set parsed_the_lines to my stringtolist ( "filter_lines" , the_lines, return )

repeat with i from 1 to length of parsed_the_lines

if item i of parsed_the_lines contains the_delimiter then

set end of cleaned_the_lines to words of item i of parsed_the_lines

end if

end repeat

--choose from list result_words_list

return cleaned_the_lines

end filter_lines

on add_comma ( theString )

set theString to theString as text --for 10.9 compatibility

set fixed_number to { }

set parsed_number to reverse of ( my stringtolist ( "add_comma" , theString, "" ) )

repeat with i from 1 to ( length of parsed_number )

set beginning of fixed_number to item i of parsed_number

if i mod 3 = 0 and i ≠ length of parsed_number then

set beginning of fixed_number to ","

end if

end repeat

log "add_commma: " & theString & " = " & my listtostring ( fixed_number, "" )

return my listtostring ( fixed_number, "" )

end add_comma

on sanitize ( data_set )

log "Sanitize did run!"

-- display dialog "\"" & data_set & "\""

set data_set to my listtostring ( emptylist ( my stringtolist ( "sanitize" , data_set, " " ) ) , " " )

-- display dialog "\"" & data_set & "\""

return data_set

end sanitize

on emptylist ( klist )

set nlist to { }

set dataLength to length of klist

repeat with i from 1 to dataLength

if item i of klist is not "" then

set end of nlist to ( item i of klist )

end if

end repeat

return nlist

end emptylist

on getTfromN ( this_number )

set this_number to this_number as string

if this_number contains "E+" then

set x to the offset of "." in this_number

set y to the offset of "+" in this_number

set z to the offset of "E" in this_number

set the decimal_adjust to characters ( y - ( length of this_number ) ) thru ¬

- 1 of this_number as string as number

if x is not 0 then

set the first_part to characters 1 thru ( x - 1 ) of this_number as string

else

set the first_part to ""

end if

set the second_part to characters ( x + 1 ) thru ( z - 1 ) of this_number as string

set the converted_number to the first_part

repeat with i from 1 to the decimal_adjust

try

set the converted_number to ¬

the converted_number & character i of the second_part

on error

set the converted_number to the converted_number & "0"

end try

end repeat

return the converted_number

else

return this_number

end if

end getTfromN

on is_number ( number_string )

try

set number_string to number_string as number

return true

on error

return false

end try

end is_number

on convertByteSize ( byteSize, KBSize, decPlaces )

if ( KBSize is missing value ) then set KBSize to 1000 + 24 * ( ( ( system attribute "sysv" ) < 4192 ) as integer )

if ( byteSize is 1 ) then

set conversion to "1 byte" as Unicode text

else if ( byteSize < KBSize ) then

set conversion to ( byteSize as Unicode text ) & " bytes"

else

set conversion to "Oooh lots!" -- Default in case yottabytes isn't enough!

set suffixes to { " KB" , " MB" , " GB" , " TB" , " PB" , " EB" , " ZB" , " YB" }

set dpShift to ( ( 10 ^ 0.5 ) ^ 2 ) * ( 10 ^ ( decPlaces - 1 ) ) -- (10 ^ decPlaces) convolutedly to try to shake out any floating-point errors.

repeat with p from 1 to ( count suffixes )

if ( byteSize < ( KBSize ^ ( p + 1 ) ) ) then

tell ( ( byteSize / ( KBSize ^ p ) ) * dpShift ) to set conversion to ( ( ( it div 0.5 - it div 1 ) / dpShift ) as Unicode text ) & item p of suffixes

exit repeat

end if

end repeat

end if

return conversion

end convertByteSize

on ms2time ( totalMS, time_duration )

set numseconds to 0

set numinutes to 0

set numhours to 0

set numdays to 0

set numyears to 0

if time_duration is "ms" then

set numseconds to totalMS div 1000

else

set numseconds to totalMS

end if

if numseconds > 86400 then

set numdays to numseconds div days

set numseconds to numseconds - ( numdays * days )

end if

if numseconds > 3600 then

set numhours to numseconds div hours

set numseconds to numseconds - ( numhours * hours )

end if

if numseconds ≥ 60 then

set numinutes to ( numseconds div minutes )

set numseconds to numseconds - ( numinutes * minutes )

end if

if numdays = 0 and numhours = 0 and numinutes = 0 then

return ( numseconds & "S" ) as text

end if

if numdays = 0 and numhours = 0 and numseconds = 0 then

return ( numinutes & "M " ) as text

end if

if numdays = 0 and numhours = 0 then

return ( numinutes & "M " & numseconds & "S" ) as text

end if

if numdays = 0 then

return ( numhours & "H " & numinutes & "M " & numseconds & "S" ) as text

else

return ( numdays & "D " & numhours & "H " & numinutes & "M" ) as text

end if

--add years

end ms2time

I also declare this in the beginning of thing script

use AppleScript version "2.4"

use scripting additions