Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine a variable's data type? How to convert to string?

I have two questions...

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 variable?

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.

like image 376
jsherk Avatar asked Dec 31 '11 21:12

jsherk


People also ask

Which method is used to convert data into strings?

toString() method converts int to String. The toString() is the static method of Integer class.

How do you determine a data type?

To check the data type of variable in Python, use the type() method. The type() is a built-in Python method that returns the class type of the argument(object) passed as a parameter. You place the variable inside a type() function, and Python returns the data type.

What does a variable's data type describe?

Variable Types A variable's type determines the values that the variable can have and the operations that can be performed on it. For example, the declaration int count declares that count is an integer ( int ).


1 Answers

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

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

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

display dialog (name of appProc)
like image 196
regulus6633 Avatar answered Sep 30 '22 16:09

regulus6633