text
stringlengths
0
15.7k
source
stringlengths
6
112
set the operator_list to {"is", "is not", "begins with", "does not begin with", "ends with", "does not end with", "contains", "does not contain", "is in", "is not in", "is equal to", "is not equal to", "is greater than", "is greater than or equal to", "is not greater than or equal to", "is less than", "is less than or equal to", "is not less than or equal to", "comes after", "comes before"}
lns3.scpt
set the selected_text to contents of selection of front document
lns3.scpt
if the selected_text begins with "{" and the selected_text ends with "}" then
lns3.scpt
set the prep_data to (characters 2 thru -2 of the selected_text) as string
lns3.scpt
set the list_items to every text item of the prep_data
lns3.scpt
set the condition_count to the count of the list_items
lns3.scpt
else -- error
lns3.scpt
my display_message()
lns3.scpt
return "script cancelled"
lns3.scpt
display dialog "Enter the name of the comparison variable:" & return & return & "ex: if this_item is \"Shoe\" then" & return & space default answer "this_item"
lns3.scpt
set the condition_variable to the text returned of the result
lns3.scpt
if the condition_variable is not "" then exit repeat
lns3.scpt
set the chosen_operator to (choose from list operator_list with prompt "Choose the comparison to use:") as string
lns3.scpt
if the chosen_operator is "false" then return "user cancelled"
lns3.scpt
repeat with i from 1 to the condition_count
lns3.scpt
if the condition_count is 1 then
lns3.scpt
set the script_text to "if " & condition_variable & space & chosen_operator & space & (item i of the list_items) & " then " & return & tab & target_string & return & "end if"
lns3.scpt
else if i is 1 then
lns3.scpt
set the script_text to "if " & condition_variable & space & chosen_operator & space & (item i of the list_items) & " then " & return & tab & target_string & return
lns3.scpt
else if i is the condition_count then
lns3.scpt
set the script_text to the script_text & "else if " & condition_variable & space & chosen_operator & space & (item i of the list_items) & " then" & return & tab & "-- item " & (i as string) & " action goes here" & return & "end if"
lns3.scpt
set the script_text to the script_text & "else if " & condition_variable & space & chosen_operator & space & (item i of the list_items) & " then" & return & tab & "-- item " & (i as string) & " action goes here" & return
lns3.scpt
my eol()
lns3.scpt
set the contents of the selection of the front document to return & return & script_text
lns3.scpt
check syntax of front document
lns3.scpt
set the replacement_string to "-- item 1 action goes here"
lns3.scpt
on display_message()
lns3.scpt
display dialog "This script creates a conditional statement for each item of a selected list. Please select text in this script that is a list of items, such as:
lns3.scpt
{\"car\", \"book\", \"house\", \"tree\"}" buttons {"Help", "OK"} default button 2 with icon 2
lns3.scpt
if the button returned of the result is "Help" then
lns3.scpt
my script_help("ScriptEditor001")
lns3.scpt
end display_message
lns3.scpt
on script_help(this_anchor)
lns3.scpt
tell application "EPSON ET-4750 Series"
lns3.scpt
«event helpsanc» this_anchor given «class sstr»:"Script Editor Help"
lns3.scpt
end script_help
lns3.scpt
on eol()
lns3.scpt
copy the (character range of selection) to {x, y}
lns3.scpt
set carriage_return to ASCII character 10
lns3.scpt
repeat with i from y to 10000000
lns3.scpt
set this_char to character i
lns3.scpt
if this_char is carriage_return then
lns3.scpt
set selection to insertion point i
lns3.scpt
return (i - 1)
lns3.scpt
set selection to insertion point (i)
lns3.scpt
end eol
lns3.scpt
set the target_string to "X-X-X"
lns3.scpt
set the script_text to the script_text & "display dialog \"" & target_string & "\" default answer \"\" buttons {\"\",\"\",\"\"} default button 1" & return
lns3.scpt
set the script_text to the script_text & "copy the result as list to {text_returned, button_pressed}" & return
lns3.scpt
if my display_message() is false then return "user cancelled"
lns3.scpt
set the contents of selection to the script_text
lns3.scpt
my replace_and_select(target_string, "")
lns3.scpt
display dialog "This script will delete the selected text." & return & return & "Do you want to continue?" buttons {"Help", "Continue", "Stop"} default button 3 with icon 2
lns3.scpt
if the user_choice is "Help" then
lns3.scpt
else if the user_choice is "Stop" then
lns3.scpt
set the script_text to the script_text & "display dialog \"" & target_string & "\" default answer \"\" buttons {\"\",\"\"} default button 1" & return
lns3.scpt
set the script_text to "display dialog \"" & target_string & "\" default answer \"\" buttons {\"OK\"} default button 1" & return
lns3.scpt
set the script_text to the script_text & "display dialog \"" & target_string & "\" buttons {\"\", \"\", \"\"} default button 3" & return
lns3.scpt
set the script_text to the script_text & "set the button_pressed to the button returned of the result" & return
lns3.scpt
set the script_text to the script_text & "if the button_pressed is \"\" then" & return
lns3.scpt
set the script_text to the script_text & tab & "-- action for 1st button goes here" & return
lns3.scpt
set the script_text to the script_text & "else if the button_pressed is \"\" then" & return
lns3.scpt
set the script_text to the script_text & tab & "-- action for 2nd button goes here" & return
lns3.scpt
set the script_text to the script_text & "else" & return
lns3.scpt
set the script_text to the script_text & tab & "-- action for 3rd button goes here" & return
lns3.scpt
set the script_text to the script_text & "end if" & return
lns3.scpt
set the script_text to the script_text & "display dialog \"" & target_string & "\" buttons {\"Cancel\", \"\", \"\"} default button 3" & return
lns3.scpt
set the script_text to the script_text & "if the button returned of the result is \"\" then" & return
lns3.scpt
set the script_text to "display dialog \"" & target_string & "\" buttons {\"\", \"\", \"\"} default button 3" & return
lns3.scpt
set the script_text to the script_text & "display dialog \"" & target_string & "\" buttons {\"\", \"\"} default button 2" & return
lns3.scpt
set the script_text to "display dialog \"" & target_string & "\" buttons {\"\", \"\"} default button 2" & return
lns3.scpt
set the script_text to "display dialog \"" & target_string & "\" buttons {\"\"} default button 1" & return
lns3.scpt
set the script_text to "display dialog \"" & target_string & "\" buttons {\"OK\"} default button 1" & return
lns3.scpt
set the script_text to "display dialog \"" & target_string & "\" buttons {\"Cancel\"} default button 1" & return
lns3.scpt
set the script_text to the script_text & "try" & CR
lns3.scpt
set the script_text to the script_text & tab & the target_string & CR
lns3.scpt
set the script_text to the script_text & "on error the error_message number the error_number" & CR
lns3.scpt
set the script_text to the script_text & tab & "set the error_text to \"Error: \" & the error_number & \". \" & the error_message" & CR
lns3.scpt
set the script_text to the script_text & tab & "-- the following line evokes the sub-routine to write the error into an error log created on the desktop" & CR
lns3.scpt
set the script_text to the script_text & tab & "-- if the file \"Script Error Log.txt\" already exists, it will add one line to the log" & CR
lns3.scpt
set the script_text to the script_text & tab & "my write_error_log(the error_text)" & CR
lns3.scpt
set the script_text to the script_text & "end try" & CR
lns3.scpt
set the script_text to the script_text & "end try" & the target_string & CR
lns3.scpt
set the sub_routine to "on write_error_log(this_error)
lns3.scpt
set the error_log to ((path to desktop) as text) & \"Script Error Log.txt\"
lns3.scpt
open for access file the error_log with write permission
lns3.scpt
write (this_error & return) to file the error_log starting at eof
lns3.scpt
close access file the error_log
lns3.scpt
end write_error_log"
lns3.scpt
if the contents of the front document does not contain "on write_error_log" then
lns3.scpt
set selection to insertion point -1 of front document
lns3.scpt
set contents of selection to CR & the sub_routine & CR
lns3.scpt
check syntax of the front document
lns3.scpt
set the script_text to the script_text & tab & "-- don't display error message if the user canceled a dialog within the [try] and [on error] lines above" & CR
lns3.scpt
set the script_text to the script_text & tab & "if the error_number is not -128 then" & CR
lns3.scpt
set the script_text to the script_text & tab & tab & "set the error_text to \"Error: \" & the error_number & \". \" & the error_message" & CR
lns3.scpt
set the script_text to the script_text & tab & tab & "display dialog the error_text buttons {\"Cancel\"} default button 1" & CR
lns3.scpt
set the script_text to the script_text & tab & "else" & CR
lns3.scpt
set the script_text to the script_text & tab & tab & "error number -128" & CR
lns3.scpt
set the script_text to the script_text & tab & "end if" & CR
lns3.scpt