Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Created by applescript_superior on 17 April 2021.
- # The script counts in binary to any integer specified by the user with the use of some cool algorithms.
- # Algorithms (methods) of finding the binary number from an integer can be found here: https://www.instructables.com/How-to-Convert-Numbers-to-Binary/
- ## enter in parameters for script to use
- set start_number to 1
- set end_number to 32
- set delay_time to 0.25
- set zero_alias to "0"
- set one_alias to "1"
- set line_width to 1
- set iteration_counter to true
- set complete_string to true
- ## insert any file path you want the cache file to be saved to (path cannot contain a space or special character)
- set cache_file_path to "Users:user:Desktop:cache.txt"
- set cache_file_posix_path to my convert_to_posix_path(cache_file_path)
- ##
- ##
- global start_number
- set version_number to "1.3.4"
- set program_title to "Binary Display"
- set iteration to 0
- global iteration
- set line_return to ASCII character 10
- global line_return
- set cache_file to open for access file cache_file_path with write permission
- global cache_file
- set tm_start to 0
- global tm_start
- set ts_start to 0
- global ts_start
- set tm_end to 0
- global tm_end
- set ts_end to 0
- global ts_end
- ##
- ##
- if iteration_counter = true then
- set iteration_counter_string to "Enabled"
- else if iteration_counter = false then
- set iteration_counter_string to "Disabled"
- end if
- set complete_string_warning to false
- if (((number of characters of zero_alias) > 1) or ((number of characters of one_alias) > 1)) then
- set complete_string to false
- set complete_string_warning to true
- set complete_string_warning_message to "** Complete String has been automatically disabled because the aliases you chose exceed one character. This feature will be implemented in a later update as a bug fix. Apologies for the inconvenience. **"
- end if
- if complete_string = true then
- set complete_string_string to "Enabled"
- else if complete_string = false then
- set complete_string_string to "Disabled"
- end if
- ##
- ##
- tell application "Terminal"
- activate
- do script "tail -f " & cache_file_posix_path & "" in window 1
- end tell
- delay 1
- ##
- ##
- try
- write "" & line_return to cache_file
- write program_title & " v" & version_number & line_return to cache_file
- write "(C)2021; applescript_superior" & line_return & line_return to cache_file
- write "Start Number: | " & start_number & line_return to cache_file
- write "End Number: | " & end_number & line_return to cache_file
- write "Delay Time: | " & (delay_time * 1000) & " ms" & line_return to cache_file
- write "Zero Alias: | \"" & zero_alias & "\"" & line_return to cache_file
- write "One Alias: | \"" & one_alias & "\"" & line_return to cache_file
- write "Line Width: | " & line_width & line_return to cache_file
- write "Iteration Counter: | " & iteration_counter_string & line_return to cache_file
- write "Complete String: | " & complete_string_string & line_return & line_return to cache_file
- if complete_string_warning = true then
- write complete_string_warning_message & line_return & line_return to cache_file
- delay 4
- end if
- delay 1
- write "[3]" & line_return to cache_file
- delay 1
- write "[2]" & line_return to cache_file
- delay 1
- write "[1]" & line_return to cache_file
- delay 1
- write line_return to cache_file
- on error
- my close_script()
- end try
- ##
- ##
- set x to end_number
- set remainder to 0
- set remainder_list to {}
- repeat
- set remainder to (round ((x / 2) - (round (x / 2) rounding down)) rounding up)
- if remainder = 0 then
- set remainder to zero_alias
- else if remainder = 1 then
- set remainder to one_alias
- end if
- set x to (round (x / 2) rounding down)
- set remainder_list to (remainder_list & remainder)
- if x < 1 then
- exit repeat
- end if
- end repeat
- set total_digits to (number of items of (reverse of remainder_list))
- ##
- ##
- try
- repeat with end_number from start_number to end_number
- set remainder to 0
- set remainder_list to {}
- set iteration to (iteration + 1)
- repeat
- set remainder to (round ((end_number / 2) - (round (end_number / 2) rounding down)) rounding up)
- if remainder = 0 then
- set remainder to zero_alias
- else if remainder = 1 then
- set remainder to one_alias
- end if
- set end_number to (round (end_number / 2) rounding down)
- set remainder_list to (remainder_list & remainder)
- if end_number < 1 then
- exit repeat
- end if
- end repeat
- set output to (reverse of remainder_list) as string
- if complete_string = true then
- set digits_needed to (total_digits - (number of characters of output))
- repeat digits_needed times
- set output to (zero_alias & output) as string
- end repeat
- end if
- delay delay_time
- set eof of cache_file to 0
- repeat line_width times
- write output to cache_file
- if iteration_counter = true then
- write " [" & iteration & "]" & line_return to cache_file
- else
- write line_return to cache_file
- end if
- end repeat
- end repeat
- on error
- set iteration to (iteration - 1)
- my close_script()
- end try
- ##
- ##
- my close_script()
- on close_script()
- write "OK; " & start_number & " to " & iteration & line_return & line_return to cache_file
- tell application "Terminal"
- do shell script "killall tail"
- end tell
- set eof of cache_file to 0
- close access cache_file
- error number -128
- end close_script
- ##
- ##
- on convert_to_posix_path(input_path)
- set search_string to ":"
- set replace_string to "/"
- set AppleScript's text item delimiters to search_string
- set input_path_items to every text item of input_path
- set AppleScript's text item delimiters to replace_string
- set input_path to input_path_items as string
- set AppleScript's text item delimiters to ""
- set input_path to replace_string & input_path
- return input_path
- end convert_to_posix_path
- ##
Add Comment
Please, Sign In to add comment