LinkingWindowsToApps.htmlTEXTVIZFG9̚{̚{ Linking windows to apps

Linking windows to apps


When should I link my window to an application ?

This functionality of Smile makes things much simpler in many of the situations where another application is involved.

- It allows to handily drive remote applications on the fly. Suppose you want to make "SurfWriter 4.7v5US 50Mb" quit on a remote machine. Choose 'Tell ...". Choose the server which is running it then choose it, in the Application chooser. Type "quit", press the 'Enter' key - you are done.

- For parts of your scripts involving another application, a window linked to it provides a convenient debugging space. You debug scripts living in other applications as easily than scripts involving AppleScript alone.

- Solution providers, or users interested in the portability of their work, will find a way of writing totally portable scripts , as explained below. This is allowed by the 'Copy translate' function ( Edit menu ), a function available for any window linked to an application.

You can link any text window to an application. You can also link script window , except those script windows which are by nature linked to Smile.
To link a window to an application, put the window in front, then choose 'tell ...' in the 'Edit' menu . This will open the Application chooser, which lists the running applications which are visible from your machine (include possibly applications running on remote machines). Choose the target application, then validate your choice. A menu appears in the bottom bar of the window, with the name of the target application. From now on, the window is linked to this application. To break the link, just choose 'Log out' in the menu of the bottom bar of the window.

How do I use a window linked to an application ?

Once a window is linked to an application, any script run from this window will behave as if it was encapsulated in a 'tell application ...' wrapper.
The 'target application' menu, in the bottom bar, displays the name of the target application. You can choose 'Dictionary' from this menu to open the dictionary of the target application. From this menu, you can also cancel the link, by choosing the 'Log out' command. This command makes the window become a standard Smile window back.
For debugging purposes, a text window with a target application still has a "context" in the sense of AppleScript. This means that you can define non-volatile variables, so that you can test a script line by line - like in the standard text window (see text window if you are not familiar with this).
Of course, when you issue a call to any of Smile's functions, you need use a 'tell application "Smile"' wrapper.

How do I make my scripts fully portable ?

Full portability is a property of scripts involving applications (it does not makes sense for scripts involving only pure AppleScript commands, possibly enriched by the terminology of Scripting Additions).

Suppose your script runs perfectly on your machine, where it uses, say, a scriptable application named "SurfWriter 4.7v5US 50Mb". When you run your script on a machine with a different version of the scriptable software, say, "SurfWriter 4.7v6", or the same version with a different file name, say, "SurfWriter 4.7v5US", it will most probably - if you take no special precaution - request from the user to find, through a standard 'Open' dialog (which displays a rather confusing prompt message, by the way), what application it must use. This can happen at the first launch of the script on a new machine, or at each launch, depending on how the script is written. This can, in certain cases, be considered a problem.

A possible solution to this problem is to store in the script, not the application name, but its signature. The script must then use the Finder to retrieve the name of the application (and launch it if necessary). Here is a short sample script which does this perfectly. It will be your responsibility to handle the error (number -1728) if the Finder does not find any application with the requested signature, or if it cannot open it.

----------------------------
set theCreator to "xxxx" -- put the creator of the application here
tell application "Finder"
set theAppName to name of application file id theCreator
if theAppName is not in name of every process then
open application file id theCreator
end if
end tell
----------------------------

The above script must run once. It stores the application name into the variable 'theAppName', and subsequent calls to the scriptable application must look like :

----------------------------
tell application theAppName
-- script here
end tell
----------------------------

Encapsulated in such a "virtual" wrapper ('theAppName' has not yet been resolved at compile time), the script cannot use the keywords of the target application - the script would not compile. The solution is : inside such a wrapper, the script must use "raw codes". Raw codes are the canonical description of the quantities that AppleScript is able to handle (properties, classes, events, constants, etc.). Usually, the user sees only the 'English-like' terminology, and AppleScript uses raw codes internally.

For example, the canonical description of the 'startup disk' property of the Finder is class sdsk.

Standard AppleScript provides little help to manipulate raw codes. This is where Smile brings a new solution. To get the raw codes, just write (or copy) the script (using the usual keywords of the application) in a window linked to the target application of the script. Preferably, use a text window.
Then, select the text of the script in this window. In the menu of the bottom bar (or in the 'Edit' menu), choose 'Copy translate' (shortcut   C).

Finally, do a 'Paste' (  V) in the "virtual" wrapper of your script. The script will come changed into raw codes. Of course, you can go back and forth between the raw codes in your script and the keywords in the window linked to the application.

If you do not know the signature of the application, launch it, then run from Smile:

----------------------------
tell application "Finder" to get creator type of process theName
----------------------------

where theName is the name of the application file.





 _!"#@'&%$#"!  ,E#F` &`&#HH-,E#F#a &a&#HH-,E#F` a F`&#HH-,E#F#a ` &a a&#HH-,E#F`@a f`&#HH-,E#F#a@` &a@a&#HH-, <<-, E# D# ZQX# D#Y QX# MD#Y QX# D#Y!!-, EhD ` E     k  1  k   k  M  k]    k    k    k  T  i  j            k      "  g  ko              /  3  y  k}            k 3  g  k w    k   g  k k  l      k  W  k   k    k    k  Y  ka    k    k    k  1  k5  o  ks    k    k    k    k    k    k    k    k    k  0  k8  :  kB    k    k  w  k    k    k    k    k    k    k  F  kN  n  kr    k    k    kE  selelist longlongpbndlist8long long.longlongBDrwfalspvistrueWIDLfalsICFFlongrSiDlongptxfTEXTGenevaptpslong Rectlist8longlonglonglongWTBHlongRqULlongLWdtlongBrWdlongAuAdfalsTbSzlong scptscptVFasdUAS 1.101.10  misccura"  CONT  misccura  cwtx  kfrmID ascr ޭ _@5@ZstylSOUP&reco2 A0cwtx