Here is a really simple example script which causes an error: System Events got an error: Can’t make item 1 of every application process whose visible = true into type string.
tell application "System Events"
repeat with appProc in (every application process whose visible is true)
display dialog appProc
end repeat
end tell
#1- How do I determine the data type of a varibale?
This would be helpful for future reference so I can figure out what kind of data type I am dealing with
#2- How do I convert the above data type to a string so it displays with display dialog? I tried adding
appProc as string
but then I get another error that says: Can’t make «class pcap» “myapplication” of application “System Events” into type string.
tell application "System Events"
repeat with appProc in (get every application process whose visible is true)
display dialog (get name of appProc)
end repeat
end tell
every application process whose… is something System Events knows, but the script does not. It has to ask SE to get this info.
For appProc same cause: SE knows what it is, but the script does not.
Also appProc is a reference, not text (which is the only thing a dialog can display). So get the name, which is text. (To see the reference look in the events log, at the bottom of the script’s window).
Generally you’d stick on “as ” to the variable to change (coerce) the data type (class). So, to get text, “as text”. The variable must be representable as text, in that case - it does not work with references, for example.
@Mark - Yes, that is great … thanks! I googled for hours and could NOT figure it out… I was googling for “data type” and similar and although there are lots of pages describing the different variable types, I could not find anything on how to determine the existing type of a variable. Maybe because it’s called a class and not a data type might have been my problem!