Re: JavaScript for automations: bug or correct behavior
Re: JavaScript for automations: bug or correct behavior
- Subject: Re: JavaScript for automations: bug or correct behavior
- From: Deivy Petrescu <email@hidden>
- Date: Tue, 20 Jan 2015 19:07:06 -0500
> On Jan 20, 2015, at 12:50 , David Steinberg <email@hidden> wrote:
>
> Hi Deivy,
>
>> So, in general, standard addition stuff like buttons will be arrays starting at 1, it that correct?
>
> This will depend on the individual addition, but whatever index you would pass in for AppleScript should also be passed in for JavaScript.
>
>> Shouldn’t the result pane show the same thing that the log pane does?
>
>
> When you log, the string containing "\n" is actually rendered and displayed, making it three lines. However, the result of the script is the string inside the language, so in JavaScript, "\n" is there, because it is part of the code. Unlike AppleScript, JavaScript does not allow for multiline strings in code.
>
> - David
>
David, thanks again.
I understand what is going on on both cases, my point is, for someone like me who does things compartmentalized, AS is AS and JS is JS.
When I write an AppleScript script, I do it with AS in my mind, while I translate to JSA and it would be great to clear the quirks out of the way from the get go.
For instance, getting the result in JS, from my string, was a big surprise.
And it took me a while to realize that may be the result pane was actually showing the JS string.
In other words, my point is, the JS for automation notes posted are great.
The notes are concise and to the point, but there might be some issues that should be mentioned.
The small differences sometimes throws people off and it should not.
For instance the following code runs smoothly in AS:
‘ tell application "Finder" to say “6” ‘
However it will balk in JSA.
finder=Application(‘Finder’)
finder.say(‘6’)
—>Error -1708: Message not understood.
It would be important to add such differences to the notes so people will not give up for minor issues.
That is just my suggestion.
Anyway, I really thank you for all your help, it is making a big difference in my strides into JSA
>> On Jan 19, 2015, at 15:55, Deivy Petrescu <email@hidden> wrote:
>>
>>
>>> On Jan 19, 2015, at 18:34 , David Steinberg <email@hidden> wrote:
>>>
>>> Hi Deivy,
>>>
>>> Though AppleScript and JavaScript differ when indexing into their own arrays, the display dialog standard addition treats 1 as the beginning of an array, so 0 won't work.
>>>
>>> - David
>>
>> David, thanks, I understand that, I just question whether this is a good idea?
>> And I understand the problem, if you change to 0, some are going to say that you broke most of the scripts, if you don’t there will be some annoying guy asking why not. (shame on me…)
>> When I originally wrote the script, I wrote in AS, i.e., I used 1 and 2, but before paying attention to what was really going on, I thought I made a mistake.
>> Surprisingly I didn’t.
>>
>> So, in general, standard addition stuff like buttons will be arrays starting at 1, it that correct?
>>
>> Well, since I got your attention, I have another question.
>> When using JS tools for text manipulation, say for instance
>>
>> texto=“This is one. This is two. This is three.”
>> nutexto=texto.replace(/\.( T)/g,’.\n$1’)
>> nutexto
>> result——>“This is one. \nThis is two. \nThis is three.”
>>
>> Which drove me nuts.
>> However :
>>
>> texto=“This is one. This is two. This is three.”
>> nutexto=texto.replace(/\.( T)/g,’.\n$1’)
>> console.log(nutexto)
>> nutexto
>> result ——>“This is one. \nThis is two. \nThis is three.”
>> log—>"This is one
>> This is two.
>> This is three.”
>>
>> Shouldn’t the result pane show the same thing that the log pane does?
>>
>>
>> Thanks!
>>
>>>> On Jan 19, 2015, at 11:21, Deivy Petrescu <email@hidden> wrote:
>>>>
>>>>
>>>> This JSA script
>>>> <script>
>>>> app=Application.currentApplication()
>>>> app.includeStandardAdditions=true
>>>> dd=app.displayDialog('Please enter your name: ', {buttons:["Cancel", "OK"], defaultButton: 1, defaultAnswer:''}).textReturned
>>>> dd
>>>> </script>
>>>>
>>>> poses a dialog where “Cancel” is the default button.
>>>> Correct behavior in AS, but JS starts its counting from 0, thus button 1 should be “OK”.
>>>> For other arrays, JSA behaves as expected.
>>>>
>>>> May be my question is if you are using JSA would that be the preferred behavior?
>>>> Thanks
Deivy Petrescu
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden