r/applescript • u/l008com • Jan 23 '24
GET the currently selected string?
I'm trying to make a super simple utility that will throw me a dialog telling me the length of the currently selected string in the frontmost app.
When I do
selection
The result is
characters 14 thru 24 of document "Selected Text Length.scpt"
And when I copy that result and paste IT into the code instead of "selection", i get a list of characters. Which is perfect because I just want to count characters anyway. But selection returns "characters 14 thru 24 of document "Selected Text Length.scpt"" as a result. How can I execute the result of selection so I can actually get the selected text?
EDIT: Turns out the answer is "contents of selection". I tried every possible phrasing I could think of to hit the magic word but I had to have someone else show me this one. Got scripting in applescript is by far the worst! But at least my script works now!
View all comments
Show parent comment
3
u/l008com Jan 23 '24
Turns out the answer was "contents of selection" ugh always a guessing game with applescript, so frustrating.