Monday, December 11, 2017

#1 2009-10-01 03:23:14 pm

Richard
Member
From:: Herefordshire, UK
Registered: 2009-09-09
Posts: 529
Website

Annoying subs

Applescript:

on subinsert_(sender)
       
       tell application "AppleScript Editor"
           activate
           set valscptsel to (contents of selection)
           if valscptsel is not "" then
               tell application "Dialog Maker" to activate
               winwarning's makeKeyAndOrderFront_(sender)
           else
               subgo("no")
               
           end if
       end tell

followed by

Applescript:

   on subgo(valcopy)
       try
           winwarning's performClose_(sender)
       end try
       set valtext to (valwintext's |string|() as string)
       
       if (valwinent's intValue()) is 0 then
           set valent to " default answer \""
           set valentdef to (valwinentdef's stringValue() as string)
           if (valwinentsec's intValue()) is 0 then
               set valentsec to "\" with hidden answer"
           else
               set valentsec to "\""
           end if
       else
           set valent to ""
           set valentdef to ""
           set valentsec to ""
       end if
       
       if (valwinbut's intValue()) is 0 then
           set valbut to " buttons {\"" & (valwinbut1's stringValue()) & "\"}"
           if (valwinbut2chk's intValue()) is 1 then
               set valbut to " buttons {\"" & (valwinbut1's stringValue()) & "\",\"" & (valwinbut2's stringValue()) & "\"}"
               if (valwinbut3chk's intValue()) is 1 then
                   set valbut to " buttons {\"" & (valwinbut1's stringValue()) & "\",\"" & (valwinbut2's stringValue()) & "\",\"" & (valwinbut3's stringValue()) & "\"}"
               end if
           end if
       else
           set valbut to ""
       end if
       
       if (valwinbutdef's indexOfSelectedItem()) is 0 then
           set valbutdef to ""
       else
           set valbutdef to " default button " & (valwinbutdef's indexOfSelectedItem())
       end if
       
       if (valwinbutcal's indexOfSelectedItem()) is 0 then
           set valbutcal to ""
       else
           if (valwinbutcal's titleOfSelectedItem() as string) is "OK" then
               set valbutcal to " cancel button 2"
           else
               set valbutcal to " cancel button " & (valwinbutcal's indexOfSelectedItem())
           end if
       end if
       
       if (valwintit's intValue()) is 0 then
           if (valwintitchs's intValue()) is 0 then
               set valtit to " with title \"" & (valwintitnam's stringValue()) & "\""
           else
               set valscptnam to (get the name of the front window of application "AppleScript Editor")
               set valtit to " with title \"" & valscptnam & "\""
               
           end if
       else
           set valtit to ""
       end if
       
       tell application "AppleScript Editor"
           activate
           set valdialog to "display dialog \"" & valtext & "\"" & valent & valentdef & valentsec & valbut & valbutdef & valbutcal & valtit --& valicon & valtmout
           (*if valcopy is "yes" then
               set the clipboard to valdialog
           else*)

           tell application "System Events"
               keystroke valdialog
           end tell
           --end if
       end tell
       tell application "Dialog Maker" to activate
   end subgo

doesn't work even with the valcopy if statement commented out but if you put the exact same contents of subgo inside the subinsert rather than calling subgo it works

the error is

2009-10-01 21:14:05.840 Dialog Maker[1933:a0f] *** -[Dialog_MakerAppDelegate subinsert:]: AppleScript Editor got an error: Can’t continue subgo. (error -1708)


Filed under: Dialog, applescript, System

Offline

 

#2 2009-10-01 03:27:47 pm

Richard
Member
From:: Herefordshire, UK
Registered: 2009-09-09
Posts: 529
Website

Re: Annoying subs

OMG please somebody explain why putting 'my' in front makes it work, nobody ever explains this! Strange how I worked it out a minute after posting XD.

Offline

 

#3 2009-10-01 03:29:48 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Annoying subs

Hi,

a common error. No application knows what a handler is, only AppleScript itself does

Applescript:

my subgo("no")


regards

Stefan

Offline

 

#4 2009-10-01 03:30:49 pm

Richard
Member
From:: Herefordshire, UK
Registered: 2009-09-09
Posts: 529
Website

Re: Annoying subs

Also a separate IBaction sub calls it fine without 'my'????

Applescript:

   on subcopy_(sender)
       subgo("yes")
   end subcopy_

Last edited by Richard (2009-10-01 03:31:59 pm)

Offline

 

#5 2009-10-01 03:34:59 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Annoying subs

The problem is the scope of the application tell block.
It's always (strongly) recommended to use application tell blocks only for lines which contain appropriate application terminology

Last edited by StefanK (2009-10-01 03:35:55 pm)


regards

Stefan

Offline

 

#6 2009-10-01 03:39:04 pm

Richard
Member
From:: Herefordshire, UK
Registered: 2009-09-09
Posts: 529
Website

Re: Annoying subs

You mean current application tells?
What appropriate application terminology?

It works perfectly now. Except for the problem in my other post.

Offline

 

#7 2009-10-01 03:46:36 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Annoying subs

I mean this

Applescript:


tell application "AppleScript Editor"
   activate
   set valscptsel to (contents of selection)
end tell
if valscptsel is not "" then
   tell application "Dialog Maker" to activate
   winwarning's makeKeyAndOrderFront_(sender)
else
   subgo("no")
end if

tell AppleScript Editor is used only for the activate and selection lines.
This avoids nested application tell blocks (Dialog Maker) and the problem with the handler call


regards

Stefan


Filed under: Dialog, applescript

Offline

 

#8 2009-10-01 04:44:48 pm

hhas
Member
Registered: 2004-04-29
Posts: 461

Re: Annoying subs

Richard wrote:

OMG please somebody explain why putting 'my' in front makes it work, nobody ever explains this! Strange how I worked it out a minute after posting XD.


A command is a command is a command. Application-defined commands like to use a different syntax to user-defined commands, but the actual mechanics are are the same. All commands within a tell block are sent to whatever object is specified by that tell block by default. Adding 'my' before the command name (which is the same as writing 'command_name() of me') informs AppleScript that you want the command sent to the current script instead.


Learn AppleScript, 3rd edition - Sanderson & Rosenthal (Apress)

Offline

 

#9 2009-10-01 06:01:36 pm

Richard
Member
From:: Herefordshire, UK
Registered: 2009-09-09
Posts: 529
Website

Re: Annoying subs

Ahhh yes, I realised that now (as in I realised just before your last comment Stefan XD), but I only realised the end tell was unnecessarily low by you telling me, I think it used to contain what is now the contents of subgo before I changed the structure to incorporate the warning window, causing this. Thanks smile

If you don't mind I would be grateful if you took a look at my weird behaviour post, because some how I don't think it's my fault. hmm lol

Last edited by Richard (2009-10-01 06:02:24 pm)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)