Wednesday, July 18, 2018

#1 2003-04-23 04:39:55 pm

Brad Bumgarner
Member
From:: Denver, Colorado
Registered: 2002-11-20
Posts: 394
Website

Contents of an empty text field / Multiple script files

I have 2 questions:

1. When I try to get the contents of a text field that is empty I get no result. How to I check for this in my script? example:

set myVar to contents of text field "Blerf" of window "Main"
if myVar > 0 then ... (* handle accordingly *)

The error I get is that myVar hasn't been defined.




2. If I have more than one Applescript file in a project, can handlers in one file be referenced (called) from the other file?

Thanks in advance,
Brad Bumgarner, CTA

Offline

 

#2 2003-04-23 04:53:42 pm

Rob
Member
From:: Ohio, USA
Registered: 2002-11-20
Posts: 1886

Re: Contents of an empty text field / Multiple script files

I have 2 questions:

1. When I try to get the contents of a text field that is empty I get no result. How to I check for this in my script? example:

set myVar to contents of text field "Blerf" of window "Main"
if myVar > 0 then ... (* handle accordingly *)

The error I get is that myVar hasn't been defined.



I have no experience with AppleScript Studio but what happens if you use something like:

Applescript:

set myVar to ""
set myVar to contents of text field "Blerf" of window "Main"
if myVar is not "" then ... (* handle accordingly *)

2. If I have more than one Applescript file in a project, can handlers in one file be referenced (called) from the other file?



I don't know within the realm of Studio apps but it seems that you should be able to use 'load script' and then call the handlers as if they were within the calling script.

Offline

 

#3 2003-04-24 01:57:23 am

julifos
Administrator
From:: Malasaña, Madrid
Registered: 2002-11-20
Posts: 2014

Re: Contents of an empty text field / Multiple script files

set myVar to contents of text field "Blerf" of window "Main"
if myVar > 0 then ... (* handle accordingly *)

The error I get is that myVar hasn't been defined.

This error jumps usually when, effectively, "myVar" hasn't been defined. You may check your window's project and make sure the object you are referring IS a text field (not, eg, a text view into a scroll view), the object IS WHITHIN the window "Main" (not, eg, into a tab view or a group box, whithin window "main"), object names ARE "Blerf" and "Main"... And such stuff, which usually takes most of the time when developing in ASS   :x

Offline

 

#4 2003-04-24 08:59:10 am

Brad Bumgarner
Member
From:: Denver, Colorado
Registered: 2002-11-20
Posts: 394
Website

Re: Contents of an empty text field / Multiple script files

Rob & jj:
I have set myVar to "" to initialize it. Same result. :?

jj:
I have checked what you suggested. I DO run into those problems, so that is always the first thing that I check. (Thanks for the reminder though.)

Thank you both for your responses. I am still looking at what I can do to "idiot proof" my application. Truth is, I'm likely to be the only user--still it doesn't hurt to do things right!

Thanks,
Brad Bumgarner, CTA

Offline

 

#5 2003-04-24 09:49:16 am

T.J. Mahaffey
Administrator
From:: Arkansas, USA
Registered: 2002-11-20
Posts: 238
Website

Re: Contents of an empty text field / Multiple script files

Brad,

Make sure you're comparing apples to oranges, so to speak.
In your first example above, you wouldn't likely be able to use a '>' operand in your conditional statement if said text field doesn't yet have anything in it.
And even if it does, it would need to be a number of some kind to be able to do a greater-than conditional, no?

Also, let me take this opportunity to reiterate *OBJECT HIERARCHY*.
Be sure your object tree is correct. ie.:

If the text field is WITHIN a tab view item, within a tab view, within a window, it is imperitive that all of those objects be represented in your statement like so:

Applescript:

set myVar to text field "foo" of tab view item "bar" of tab view "kung" of window "fu"

And, as JJ said, make sure you're talking to a text field and not some other type of text-container.

Post again with more complete code if you need further help. I'm sure we can figure it out and get you on your way.
wink


T.J.
tj@tjmahaffey.com

Offline

 

#6 2003-04-24 10:18:10 am

Brad Bumgarner
Member
From:: Denver, Colorado
Registered: 2002-11-20
Posts: 394
Website

Re: Contents of an empty text field / Multiple script files

Make sure you're comparing apples to oranges, so to speak.
In your first example above, you wouldn't likely be able to use a '>' operand in your conditional statement if said text field doesn't yet have anything in it.
And even if it does, it would need to be a number of some kind to be able to do a greater-than conditional, no?


I have just confirmed that I am using a text field (NSTextField). I have a number formatter attached to it, so it does return a number.

Also, let me take this opportunity to reiterate *OBJECT HIERARCHY*.
Be sure your object tree is correct. ie.:

If the text field is WITHIN a tab view item, within a tab view, within a window, it is imperitive that all of those objects be represented in your statement


I have created a basic window. I am not using any tabs. I have learned the hard way about "the reference to the reference to the reference, etc., etc." in applescript. In the beginning (about 5-6 years ago), that slowed me down more than anything. I KNEW what I was referring to, why didn't the computer? wink

Thanks again,
Brad Bumgarner, CTA

Offline

 

#7 2003-04-24 10:21:05 am

Brad Bumgarner
Member
From:: Denver, Colorado
Registered: 2002-11-20
Posts: 394
Website

Re: Contents of an empty text field / Multiple script files

you wouldn't likely be able to use a '>' operand in your conditional statement if said text field doesn't yet have anything in it.



An additional thought: I will try checking for a "" condition BEFORE checking the number value.

Offline

 

#8 2003-04-24 10:38:22 am

julifos
Administrator
From:: Malasaña, Madrid
Registered: 2002-11-20
Posts: 2014

Re: Contents of an empty text field / Multiple script files

Have you tried retrieving info from outside of your app? Try this from any script editor:

Applescript:

tell app "Whatever called your app"
properties of text field "Blerf" of window "Main"
end tell

Defiitivelly, if you don't receive its properties, you're not targetting OK such text field... But if you do, what do you see in property "contents"? :idea:

Offline

 

#9 2003-04-24 11:00:59 am

Brad Bumgarner
Member
From:: Denver, Colorado
Registered: 2002-11-20
Posts: 394
Website

Re: Contents of an empty text field / Multiple script files

Have you tried retrieving info from outside of your app? Try this from any script editor:

Code:

tell app "Whatever called your app"
     properties of text field "Blerf" of window "Main"
end tell

Defiitivelly, if you don't receive its properties, you're not targetting OK such text field... But if you do, what do you see in property "contents"?
_________________
jj
MacScripter


EXCELLENT SUGGESTION!! big_smile

When the text field was empty the contents show up as "missing value", however, the another property, double value returned 0.0 (as a number). Instead of pulling the contents, I will now pull the double value. Works for an empty text field as well as a text field with info. Next step, confirm that the formatter handles alpha character input properly (i.e. not allow it--I need dollor amounts in this field).


Thanks for all the help and suggestions,
Brad Bumgarner,  CTA

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)