Thursday, June 29, 2017

#26 2014-10-27 07:07:30 am

McUsrII
Member
Registered: 2012-11-20
Posts: 3046
Website

Re: [Tutorial] Scripting Libraries

Hello.

I am currently writing some sdef files, and I have a couple of questions:

I have some handlers that takes a list of lists of integers as a parameter (a matrix), how do I specify that?

Am I right in that it is better to not specify the return type, than do so for a command?

I also wonder how you specify an AppleScript Object as a parameter.

Thanks.

Last edited by McUsrII (2014-10-27 07:07:54 am)


Filed under: Script Libraries, 2.3

Offline

 

#27 2014-10-27 07:13:48 am

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 5024

Re: [Tutorial] Scripting Libraries

McUsrII wrote:

I have some handlers that takes a list of lists of integers as a parameter (a matrix), how do I specify that?

A list of any. That's the best you can do.

Am I right in that it is better to not specify the return type, than do so for a command?

If you know the type, by all means specify it.

I also wonder how you specify an AppleScript Object as a parameter.

Usually as any.

In script libraries, types are purely informative -- they don't actually do anything, unlike in apps and scripting additions. So just use common sense, and add explanations where you think they will help.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#28 2014-10-27 07:59:23 am

McUsrII
Member
Registered: 2012-11-20
Posts: 3046
Website

Re: [Tutorial] Scripting Libraries

Hello.

Thanks a whole lot Shane. I was really wondering about this. My qualms with return types, is of course when the return types varies, which isn't good practice, but which choose from list for instance uses anyway. smile


Filed under: Script Libraries, 2.3

Offline

 

#29 2014-11-04 07:23:48 am

McUsrII
Member
Registered: 2012-11-20
Posts: 3046
Website

Re: [Tutorial] Scripting Libraries

Hello.

I am at a loss,wondering about how I make scripting terminology for a handler that takes no parameters, if that is possible.

It doesn't just work by leaving out the direct parameter definition, and any other parameter description. I hope I have overlooked something.


Filed under: Script Libraries

Offline

 

#30 2014-11-04 08:49:06 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2656

Re: [Tutorial] Scripting Libraries

Most simplest form of a command is like:

[code]<command name="command name" code="suitcomm" />[/code]
where the implementation is like:

Applescript:

on command name
return true
end command name

which should be used like

Applescript:

use script "name of library"

set x to command name

p.s. Tested and worked in Mavericks

Last edited by DJ Bazzie Wazzie (2014-11-04 08:49:52 am)

Offline

 

#31 2014-11-04 09:20:47 am

McUsrII
Member
Registered: 2012-11-20
Posts: 3046
Website

Re: [Tutorial] Scripting Libraries

Hello.

I can't compile anything like that, maybe I am doing something wrong, (I get the message: Expected «given», «into», «with», «without» or other parametername, but found end of line) I am on Mavericks too.

Applescript:

use AppleScript version "2.3"
use scripting additions
use framework "Foundation"
use framework "AppKit"

(* ========== debug suite ========== *)
on milli secs
# from start
   tell current application to set this_time to (its NSDate's timeIntervalSinceReferenceDate()) * 1000
   return this_time
(*
   if start = 0 then
       return this_time
   else
       return (this_time - start)
   end if
*)

   # NSDate's alloc()'s init() to return ((its timeIntervalSince1970()) * 1000)
end milli secs

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary>
    <suite name="Debug Suite" code="DsUi" description="Debug Suite contains a series of commands that can be used to  help debug AppleScripts.">
         <command name="milli secs" code="DsUiMsEc" >
         </command>
    </suite>
</dictionary>

Offline

 

#32 2014-11-04 10:27:48 am

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

Re: [Tutorial] Scripting Libraries

from the Cocoa Scripting documentation

Cocoa scripting will generate default keys for property and element attributes and for commands, if you do not specify them. For a property, it capitalizes each word of the property’s name except the first word, then removes any spaces. For an element, it specifies the plural of the element type. For a command, the default is NSScriptCommand

apart from that, the handler parentheses are missing

Applescript:

on milliSecs()


regards

Stefan

Offline

 

#33 2014-11-04 10:35:55 am

McUsrII
Member
Registered: 2012-11-20
Posts: 3046
Website

Re: [Tutorial] Scripting Libraries

Hello Stefan.

Thanks for the input, I had a question earlier in this thread regarding parenthesis, and by the answer I got from Shane, I figured I couldn't use parenthesis with a command that is supported with terminology.

Edit

I asked the question in post #9, and Shane answered it in post #11, (page 1 big_smile ).


The motivation, is of course to have the terminology load with the use script clause, so I won't have to use a script object in order to utilize the commands, but can use them like I can with a scripting additions command.

For the record, the script bundle is named corelibrary, the sdef file is named corelibrary.sdef, the name in the bundle tab is corelibrary, and the id is net.mcusr.corelibrary. ASOBJC is enabled, and the sdef document a valid sdef/xml utf-8 document.

Last edited by McUsrII (2014-11-04 10:39:39 am)

Offline

 

#34 2014-11-04 10:39:14 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2656

Re: [Tutorial] Scripting Libraries

McUsrII wrote:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary>
    <suite name="Debug Suite" code="DsUi" description="Debug Suite contains a series of commands that can be used to  help debug AppleScripts.">
         <command name="milli secs" code="DsUiMsEc" >
         </command>
    </suite>
</dictionary>

your sdef should have an empty command tag if it is really empty, I guess it uses libxml to parse the file because in libxml there is a difference between <tab></tag> and <tag />. So you sdef should look like:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary>
    <suite name="Debug Suite" code="DsUi" description="Debug Suite contains a series of commands that can be used to  help debug AppleScripts.">
         <command name="milli secs" code="DsUiMsEc" />
    </suite>
</dictionary>

StefanK wrote:

apart from that, the handler parentheses are missing

Not when you use your own scripting definition, parentheses are not needed then.

Last edited by DJ Bazzie Wazzie (2014-11-04 10:40:41 am)

Offline

 

#35 2014-11-04 10:41:53 am

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

Re: [Tutorial] Scripting Libraries

sorry, I was wrong, forget the other post


regards

Stefan

Offline

 

#36 2014-11-04 10:42:51 am

McUsrII
Member
Registered: 2012-11-20
Posts: 3046
Website

Re: [Tutorial] Scripting Libraries

Hello.

Thanks for answering DJ Bazzie Wazzie, I have tried that as well.  smile

Offline

 

#37 2014-11-04 10:47:18 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2656

Re: [Tutorial] Scripting Libraries

McUsrII wrote:

Hello.

Thanks for answering DJ Bazzie Wazzie, I have tried that as well.  smile

At least it works on my machine only when you write an empty tag as <tagname /> otherwise it won't work.

What I did was
1) create new applescript in script editor
2) save script as script bundle
3) a bundle inspector (drawer) appears, open it
4) create sdef file with plain text editor (sublime text)
5) drag & drop the sdef file inside the bundle
6) fill in the name (without extension) in the sdef field name in the drawer
7) save the file again
8) write the handler as below

on milli secs
return 0
end milli secs

9) compile (the handler should compile properly)

Last edited by DJ Bazzie Wazzie (2014-11-04 10:49:31 am)

Offline

 

#38 2014-11-04 11:11:31 am

McUsrII
Member
Registered: 2012-11-20
Posts: 3046
Website

Re: [Tutorial] Scripting Libraries

Hello.


I have done what you have done, and I have also tried with/without use AppleScript version "2.3"
But it just doesn't work. (I also added a title tag to the dictionary.)

Offline

 

#39 2014-11-04 11:26:22 am

McUsrII
Member
Registered: 2012-11-20
Posts: 3046
Website

Re: [Tutorial] Scripting Libraries

Hello.


Restarting ScriptEditor and closing bundles with various earlier attempts , and "test scripts", made sure of that there wasn't any conflicting terminology around, and it worked!

Thanks smile

I did  add "use AppleScript version "2.3" " in addition to following DJ Bazzie Wazzie's receipe to the point.

Offline

 

#40 2014-11-04 04:56:01 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 5024

Re: [Tutorial] Scripting Libraries

DJ Bazzie Wazzie wrote:

At least it works on my machine only when you write an empty tag as <tagname /> otherwise it won't work.

I'm a bit surprised by this. The reason is because I went back and looked at the sdef for ASObjC Runner, which does this very thing for several commands, and they all work fine.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#41 2014-11-05 04:25:58 am

McUsrII
Member
Registered: 2012-11-20
Posts: 3046
Website

Re: [Tutorial] Scripting Libraries

Hello.

It's surprising that you have to use an "empty tag" though, when there is nothing to be put inside the command tag.

Hindsightly I guess I had saved some hours if I had started out with AppleScriptObjC Explorer in the first place. I managed to wreak havoc with AppleScript Editor over the course, and I actually had to restart it, not only close the script bundle, which I had figured up front I never would have, as long as I didn't add the script bundle to the dictionary library of AppleScript Editor. Now things are working great, and thanks for all your help and patience! smile

Edit

The main take away from me besides using "empty tags", when there wasn't any content to put within has been the cycle:

1. Edit and save the sdef file.
2. Save the bundle.
3. Add your applescript handler to the bundle.
4. Save and test the bundle.

Last edited by McUsrII (2014-11-05 05:52:36 am)

Offline

 

#42 2014-11-05 05:38:59 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2656

Re: [Tutorial] Scripting Libraries

McUsrII wrote:

It's surprising that you have to use an "empty tag" though, when there is nothing to be put inside the command tag.

UPDATE: It seems that once it compiled it doesn't matter?

Looking further into this...

Last edited by DJ Bazzie Wazzie (2014-11-05 05:43:22 am)

Offline

 

#43 2014-11-05 05:49:55 am

McUsrII
Member
Registered: 2012-11-20
Posts: 3046
Website

Re: [Tutorial] Scripting Libraries

Hello.

I think I'll just use what you call an "empty" tag, when there are nothing like direct-parameter and other parameters inside the command block. It's a good rule of thumb, particularily, when Shane's AsObjC Explorer creates such sdef definitions for such commands.

I think I may have really littered Script Editor in the process, but now the process is controllable again. smile

When there is no dictionary added to the library of AppleScript Editor, no script in the editor , that uses the library bundle I am editing in  the editor; then  edititing the  sdef, saving the bundle, adding the  handler, then compiling the bundle, and re-saving it works well!

This even works if I have to change words in the command or parameters, due to having used some reserved word, like "using" for instance, and re compile, works like a charm now!

Last edited by McUsrII (2014-11-05 06:22:34 am)

Offline

 

#44 2014-11-05 06:08:57 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2656

Re: [Tutorial] Scripting Libraries

I think I'm losing my mind here neutral

Yesterday, behind the same machine I couldn't compile your sdef file and when changed it into <command \> I could compile it. When I set it back to <command></command> tag it wouldn't compile again just to make sure that it was the problem. And again when set to <command /> style it would compile. Because I was working with libxml2, and it does have a difference between these two (the check for empty tag will return true for <command \> and will return false <command></command>), I assumed there is a difference for script libraries as well. But today I wanted to get the same "error" again and everything compiles just fine, even without extra saving. So I guess it has to do with some caching or something in the background.

Einstein once said: "Insanity is doing the same thing over and over again and expecting different results.". I'm in doubt if I'm going insane or Mavericks big_smile.

Offline

 

#45 2014-11-05 06:09:44 am

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 5024

Re: [Tutorial] Scripting Libraries

McUsrII wrote:

It's a good level of thumb, particularily, when Shane's AsObjC Explorer creates such sdef definitions for such commands.

FWIW, I just use:

Applescript:

NSData *sdefData = [self.sdefXMLDocument XMLDataWithOptions:NSXMLDocumentTidyXML];

The only messing with XML I do is when I read in an existing sdef, in which case I turn all type attributes into elements, because it makes the interface simpler. And of course the table handles things like escaping reserved characters.

You young 'uns have it easy wink In the old pre-Mavericks days, the slightest mistake in an sdef would usually mean at least quitting and relaunching your editor. After much begging, sdef file modification dates are now compared and caches cleared if necessary.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#46 2014-11-05 06:12:23 am

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 5024

Re: [Tutorial] Scripting Libraries

DJ Bazzie Wazzie wrote:

I think I'm losing my mind here

Well it was you or me, so I'm happy tongue


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#47 2014-11-05 06:25:30 am

McUsrII
Member
Registered: 2012-11-20
Posts: 3046
Website

Re: [Tutorial] Scripting Libraries

Hello.

I believe what ruined  it totally for me yesterday, was having several scriptbundles, with almost the same terminology, and some driver scripts as well. I guess I managed somehow to trash the cache, but I am not looking back into it.

Next time I get serious issues, I'll restart the Script Editor and take it from there.

Thanks for the tidy xml command Shane, I didn't know it convert tags! smile

Last edited by McUsrII (2014-11-05 06:25:47 am)

Offline

 

#48 2014-11-05 06:34:27 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2656

Re: [Tutorial] Scripting Libraries

Shane Stanley wrote:

DJ Bazzie Wazzie wrote:

I think I'm losing my mind here

Well it was you or me, so I'm happy tongue

Found it!

I was having cache issue. It seems that the running instance of AppleScript loves to cache script libraries and it's definition files. Even when I remove the a script library and then create a new one with the same specs the errors will be thrown on my screen knowing it shouldn't give an error in the first place. I need to logout and login again in order to make the script compile again. I will look into this if Yosemite have these cache issues as well.

In short: The first steps I posted previously is very important you do them correctly the first time! If not, there is no way you can make the scripting definition to load properly and you're forces to start over or re-login to the system. I will take these steps in side note in the tutorial as well.

Offline

 

#49 2014-11-05 04:35:14 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 5024

Re: [Tutorial] Scripting Libraries

FWIW, one of the biggest caching gotchas is that the modification date check is done with the app or library, not the sdef file. Changing a file inside a bundle doesn't always change the bundle's modification date. Even saving over an existing bundle doesn't always change the bundle's modification date, either. So you need to think about doing something like touching the library.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#50 2014-11-12 05:58:43 am

McUsrII
Member
Registered: 2012-11-20
Posts: 3046
Website

Re: [Tutorial] Scripting Libraries

Hello.

I tried to run a pair of empty tags thru an xml validator, and it validated just fine. And so does a single empty tag.

We all know that we should use single empty tags, but I was curious and that is why I post the result.

The conclusion is that sdef is based on tidied xml, and just not xml.

And now, over to the chess world championship. smile

Last edited by McUsrII (2014-11-12 05:59:01 am)


Filed under: xml, sdef

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.115 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)