Marco
Rotatori
2.0

Share
different

HOME SOFTWARE CODE EXTRAS PERSONAL CONTACTS

Source code


In this page you can find some source code.
There aren't the sources of my applications, but portions of useful or interesting code.
Currently there are only AppleScript functions for many and different uses. All the AppleScripts can be downloaded to view the code and to use them.
You can freely use and distribute them mentioning, if possible, me.
You can contact for comments, suggestions, bug reports, etc…
If you want to support me, you can make a donation by clicking on the link below.
Thank you!


To use these AppleScript functions you must include the code into your AppleScript.
If you want to use more than one function in the same script you must verify the name of the variables because they could be equals.



split()


This function permits you to divide a string in a list of more strings using a delimiter.
It requires two arguments: the first is the text delimiter and it must be a string, usually it's only a character, and the second is the string to divide and it also must be a string.
The result of the function is a list of strings.

 -- example 
 set myList to split(":", "Key:value") 
 -- result: {"Key", "value"} 



replace()


This function permits you to replace a text into a string with another text.
It requires three arguments and everyone must be a string: the first is the text to replace, the second is the new text to insert and the last is the string to modify.
All matched texts in the string are replaced.
The result of the function is the replaced string.

 -- example 
 set htmlString to replace(">", ">", "Greater than = >") 
 -- result: "Greater than = >" 



byteValue()


This function converts an original number of bytes in the respective size of its multiples.
The final size is converted in KB, MB, GB, ect. dividing byte for 1024 until the correct muliple.
The result of the function is a list of two element: the first is a real number with two decimal digits and the secont is a string with the corresponding multiple.

 -- example 
 set sizeOfFile to byteValue(45385) 
 -- result: {44.32, "KB"} 



dec2bin(), dec2hex(), bin2dec(), hex2dec()


These functions converts a decimal number to corresponding binary or hexadecimal value, or from binary or hexadecimal value to decimal number.
The conversions to binary or hex value return a value with the least number of digits.
The firsts two functions required a decimal number and return respectively a string of the binary and hex value, and the other two functions required a string with the binary or hex value and their result is a number.

 -- examples 
 set binaryNumber to dec2bin(36) 
 -- result: "100100" 
 set hexNumber to dec2hex(365) 
 -- result: "16D" 
 set numberFromBin to bin2dec("01011001") 
 -- result: 89 
 set numberFromHex to hex2dec("C3AFF2") 
 -- result: 12824562 



addZero()


This function add one or more zero befor a number.
It is useful to make numerators with the same number of digits.
The function requires two arguments, both as number: the first is the original number and the second is the number of digits must return. If the new number of digits is less than the number of digits of the original number then the result is simply the original number as string.
The result of the function is a string of the number preceded with some zero.

 -- example 
 set myNumerator to addZero(26, 5) 
 -- result: "00026" 



removeFromList()


This function remove an item from a list.
It requires two arguments: the first is the item to remove and the second is the list to modify.
The result of the function is a list without the item.

 -- example 
 set newList to removeFromList("Marco", {"George", "Marco", "Lucas"}) 
 -- result: {"George", "Lucas"} 



isEven()


This function control if a number is even.
The result of the function is a boolean: if the number is even return true else return false.

 -- example 
 set var to isEven(5) 
 -- result: false 



Made on a Mac || Optimized for Safari || Last update: 20-06-2010

© 2010