You are not logged in.
In Applescript 2.4, some of the examples in the first script return something very different.
It´s seems that, even though I have the same TID "", AS recognizes "-" and "*" as a TID; and don't consider "_" as a word.
(If I ask for "length of Applescript's text item delimiters" the answer is: 1)
Applescript:
words of "Hi, I'm Peggy-Sue" --> {"Hi", "I'm", "Peggy-Sue"}
-- {"Hi", "I'm", "Peggy", "Sue"}
words of "Now*is the.time&for all_good (folks) to learn-AppleScript"
--> {"Now", "*", "is", "the.time", "&", "for", "all", "_", "good", "folks", "to", "learn-AppleScript"}
-- {"Now", "is", "the.time", "for", "all_good", "folks", "to", "learn", "AppleScript"}
words of "set-piece is hyphenated" --> {"set-piece", "is", "hyphenated"} - the hyphen isn't separated
-- {"set", "piece", "is", "hyphenated"} (now it's not)
words of "funny*word with asterisk" --> {"funny", "*", "word", "with", "asterisk"} - the asterisk is separate
-- {"funny", "word", "with", "asterisk"}
Offline
Hello, first of all, that tutorial is awesome, it gave me great new ideas for my application (btw I'm creating a calculator).
I am referring to the first part of the tutorial, the "word of" part. For the "minus", "times" and "divided by" section of the calculator I can't get the second word, which would be "-", "*" or "/". Here's my code for the 4 basics.
Applescript:
set response to text returned of (display dialog "Enter one of the 4 basic arithmetic operations
(+, -, *, /)" default answer "" buttons {"Continue"} default button 1 with title "Basic arithmetic operations")
set a1 to the result
try
repeat with aCharacter in response
if (aCharacter as text) is not in allowedAll then
display dialog "Please enter numbers only" buttons {"OK"} cancel button 1 default button 1
end if
if (word 2) of a1 is "+" then
set a2 to (word 1) of a1
set a3 to (word 3) of a1
set a4 to a2 + a3
display dialog a2 & " + " & a3 & " = " & a4 with title "Result" buttons {"Copy result to clipboard", "Okay"} default button 2
if the button returned of the result is "Okay" then
exit repeat
else
set the clipboard to a3 as text
exit repeat
end if
else if (word 2) of a1 is "-" then
set a2 to (word 1) of a1
set a3 to (word 3) of a1
set a4 to a2 - a3
display dialog a2 & " - " & a3 & " = " & a4 with title "Result" buttons {"Copy result to clipboard", "Okay"} default button 2
if the button returned of the result is "Okay" then
exit repeat
else
set the clipboard to a3 as text
exit repeat
end if
else if (word 2) of a1 is "*" then
set a2 to (word 1) of a1
set a3 to (word 3) of a1
set a4 to a2 * a3
display dialog a2 & " ・ " & a3 & " = " & a4 with title "Result" buttons {"Copy result to clipboard", "Okay"} default button 2
if the button returned of the result is "Okay" then
exit repeat
else
set the clipboard to a3 as text
exit repeat
end if
else if (word 2) of a1 is "/" then
set a2 to (word 1) of a1
set a3 to (word 3) of a1
set a4 to a2 / a3
display dialog a2 & " : " & a3 & " = " & a4 with title "Result" buttons {"Copy result to clipboard", "Okay"} default button 2
if the button returned of the result is "Okay" then
exit repeat
else
set the clipboard to a3 as text
exit repeat
end if
end if
end repeat
exit repeat
end try
But as I said, that doesn't work with the "minus", "times" and "divided by" section. So I tried this workaround, as described in the tutorial
Applescript:
set a1 to "4/2"
set x to AppleScript's text item delimiters
set AppleScript's text item delimiters to ASCII character 47 -- (that's the slash)
return word 2 of a1
set AppleScript's text item delimiters to x
but that still returnes 2, which is supposed to be the third word
Your help is greatly apprechiated
Last edited by collin (2015-10-29 03:46:45 pm)
Offline
Glad you liked the tutorial, Colin. Your problem is that "/", "*", etc. are not words in AppleScript, they are characters.
Try this:
Applescript:
set theString to "a / c . e"
set W to words of theString --> "a", "c", "e"
as you see, only the letters (separated by spaces) show up. You'll have to hunt for those characters specifically.
Hello, first of all, that tutorial is awesome, it gave me great new ideas for my application (btw I'm creating a calculator).
I am referring to the first part of the tutorial, the "word of" part. For the "times" and "divided by" section of the calculator I can't get the second word, which would be "*" or "/". Here's my code for the 4 basics.Applescript:
set response to text returned of (display dialog "Enter one of the 4 basic arithmetic operations
(+, -, *, /)" default answer "" buttons {"Continue"} default button 1 with title "Basic arithmetic operations")
set a1 to the result
try
repeat with aCharacter in response
if (aCharacter as text) is not in allowedAll then
display dialog "Please enter numbers only" buttons {"OK"} cancel button 1 default button 1
end if
if (word 2) of a1 is "+" then
set a2 to (word 1) of a1
set a3 to (word 3) of a1
set a4 to a2 + a3
display dialog a2 & " + " & a3 & " = " & a4 with title "Result" buttons {"Copy result to clipboard", "Okay"} default button 2
if the button returned of the result is "Okay" then
exit repeat
else
set the clipboard to a3 as text
exit repeat
end if
else if (word 2) of a1 is "-" then
set a2 to (word 1) of a1
set a3 to (word 3) of a1
set a4 to a2 - a3
display dialog a2 & " - " & a3 & " = " & a4 with title "Result" buttons {"Copy result to clipboard", "Okay"} default button 2
if the button returned of the result is "Okay" then
exit repeat
else
set the clipboard to a3 as text
exit repeat
end if
else if (word 2) of a1 is "*" then
set a2 to (word 1) of a1
set a3 to (word 3) of a1
set a4 to a2 * a3
display dialog a2 & " ・ " & a3 & " = " & a4 with title "Result" buttons {"Copy result to clipboard", "Okay"} default button 2
if the button returned of the result is "Okay" then
exit repeat
else
set the clipboard to a3 as text
exit repeat
end if
else if (word 2) of a1 is "/" then
set a2 to (word 1) of a1
set a3 to (word 3) of a1
set a4 to a2 / a3
display dialog a2 & " : " & a3 & " = " & a4 with title "Result" buttons {"Copy result to clipboard", "Okay"} default button 2
if the button returned of the result is "Okay" then
exit repeat
else
set the clipboard to a3 as text
exit repeat
end if
end if
end repeat
exit repeat
end try
But as I said, that doesn't work with the "times" and "divided by" section. So I tried this workaround, as described in the tutorial
Applescript:
set a1 to "4/2"
set x to AppleScript's text item delimiters
set AppleScript's text item delimiters to ASCII character 47 -- (that's the slash)
return word 2 of a1
set AppleScript's text item delimiters to x
but that still returnes 2, which is supposed to be the third word
![]()
Your help is greatly apprechiated
Mac mini running 10.14.6, 2011 27" iMac as display.
Offline