• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Weird behavior - Script saved as application...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Weird behavior - Script saved as application...


  • Subject: Re: Weird behavior - Script saved as application...
  • From: Paul Berkowitz <email@hidden>
  • Date: Fri, 07 Apr 2006 13:36:11 -0700
  • Thread-topic: Weird behavior - Script saved as application...

Title: Re: Weird behavior - Script saved as application...
On 4/7/06 1:01 PM, "Bernardo Höhl" <email@hidden> wrote:

Hi List,

Why does this script work when I run it from script editor, and when I save it as an application doesn't?

I get:

"Every character of 7 doesn't understand the count message."

Thanks!

Bernardo Höhl
Rio de Janeiro - Brazil


set currentDate to (current date)
set dataDeHoje to formatDate(currentDate)

on formatDate(_date)
    set _day to day of _date
    
    if (count of characters of _day) as text < 2 then
        set _day to "0" & _day
    end if
    
    set _month to month of _date as number
    if (count of characters of _month) as text < 2 then
        set _month to "0" & _month
    end if
    
    set _year to year of _date
    display dialog _day & "." & _month & "." & _year
    
end formatDate

Your parentheses are all wrong.

     set _day to day of _date
    
The result is an integer (like 23), not text. So

    
(count of characters of _day)

should error, since an integer does not have any characters. But in  a script editor, at least, the result is 0, not an error. The script editor (Script Debugger does the same thing) is doing some sort of coercion here. 'count of' is actually itself an alternative form of the command 'count' - it's not a property. So  I guess it's counting the symbol 7 or something like that - the result is always 0. I suspect that the command 'count' is being directed to the application running the script - Script Editor - which is scriptable. so instead of getting  an error you're getting whatever Script Editor has been programmed to do for counting an integer - 0. When saved as an application, you get the error, as you should. In either case you ought to realize you're not getting the answer you want. In Script Editor, where the result is 0, the bad parentheses you're using then gets you this:

    (count of characters of _day) as text
   --> 0 as text
    --> "0"

which is, of course less than 2. But you're going to get the exact same result ("0") if _day = 23.

set _day to 23
(count of characters of _day)
-->0

set _day to 23
(count of characters of _day) as text
--> "0"


What you really want, I think is



    count of characters of (_day as text)
    --> 1

because

    _day = 7

    _day as text
    --> "7"

When _day = 23 _day as text = "23" and the count is 2.

That's what you actually want, right?

You're making the identical mistake with _month. Should be

    if count of characters of (_month as text) < 2 then


--
Paul Berkowitz
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Weird behavior - Script saved as application...
      • From: kai <email@hidden>
References: 
 >Weird behavior - Script saved as application... (From: Bernardo Höhl <email@hidden>)

  • Prev by Date: Re: Store script as run only
  • Next by Date: Re: Weird behavior - Script saved as application...
  • Previous by thread: Re: Weird behavior - Script saved as application...
  • Next by thread: Re: Weird behavior - Script saved as application...
  • Index(es):
    • Date
    • Thread