How to determine the data type of variables? How to convert to string?

I have two questions ...

Here is a really simple example script that throws an error:

System events received an error message: Cant makes element 1 of each application process, whose visibility = true in the 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 to determine the data type of a variable?

This would be useful for future reference, so I can figure out what type of data I am facing

2- How to convert the above data type to string so that it is displayed with a display dialog?

I tried adding:

 appProc as string 

but then I get another error that says:

Cannot make "class pcap" "myapplication" of the System Events application into a type string.

+8
variables types applescript
source share
1 answer

To get the data type ... use the class ...

 set a to "some text variable" return class of a 

Convert to string? ... try "as text" or "as a string." It basically works. However, in your case, appProc has properties (as mentioned in Red_menace), and you want to display its name property ...

 display dialog (name of appProc) 
+11
source share

All Articles