Team LiB   Previous Section   Next Section
File Exchange

Syntax

tell app "File Exchange"

   get version -- returns something like "3.0.3"

end tell

Dictionary commands

run

Sending File Exchange this command is the same as double-clicking it in the System Folder:Control Panels folder, but run will have no effect if the control panel is already open. Just including:

app "File Exchange"

in a tell statement sends the app an implicit run command if it is not already open.

reopen

This command has no discernible effect on the application when it is already open.

quit

This command quits the File Exchange application.

make

Use this command to make a new extension mapping by passing it a record containing the properties for the new mapping.

new extension mapping

This identifies the new object you are creating with script, as in:

make new extension mapping

with properties record

with properties provides the properties for the new extension mapping. This code example makes sure that BBEdit opens the PC files with .htm extensions on my machine:

tell application "File Exchange"



make new extension mapping with properties {PC extension:¬



"htm",  creator type:"R*ch", file type:"TEXT"}



end tell
delete

This deletes a certain extension mapping or translation mapping. The following example searches the first 10 extension mappings for the PC extension "8med"; if this is found, the extension mapping is deleted and the applet lets the user know about it with the display dialog osax. Appendix A, covers the scripting additions. Chapter 7, covers the repeat statement.

tell application "File Exchange"

  repeat with m from 1 to 10

    if (PC extension of extension mapping m) is equal to¬

"8med" then

      delete extension mapping m

      display dialog "Deleted 8med"

      exit repeat

    end if

  end repeat

end tell

mount now

This command immediately mounts on the desktop any available PC SCSI volumes, or returns zero if your computer is not networked to any PC disks.

Dictionary classes

application

This class represents the File Exchange application, as in:

tell app "File Exchange" to get version

The two elements, extension and translation mapping, represent what the user can accomplish with the two tabbed panels of the File Exchange control panel: PC Exchange and File Translation.

The following are application elements:

extension mapping

This represents the mapping of a PC extension like .doc to an application on the computer. You can identify the various extension mappings by their index, as in:

extension mapping 1

The prior multi-line example iterates through the first 10 extension mappings with a repeat statement, looking for a mapping that uses the extension "8med." This mapping is then summarily deleted. See the extension mapping class for a description of its properties.

translation mapping

File Exchange also has numerous translation mappings, which represent the mapping of a file type like 'TEXT' to an application, like AppleWorks 6. You can identify these mappings by their index as in translation mapping 5. See the translation mapping class description.

The following are application properties:

name (international text; read-only)

The application name is "File Exchange."

frontmost (boolean; read-only)

This is a true/false value indicating whether the application is the active program on the desktop.

version (version object; read-only)

This returns the File-Exchange program version as the version number surrounded by double quotes, as in "3.0.3." You can display the control panel version in the Script Editor results window with the following code:

tell app "File Exchange" to get version

Chapter 2, is devoted to Script Editor.

current panel (PC exchange or file translation)

This command will return or set either of these constants depending on which of the File Exchange tabbed panels is active at the time.

mapping PC extensions (boolean)

You can automatically turn on or off the mapping of PC extensions like .doc or .htm to Mac creator and file types by setting this property. This is equivalent to the "Map PC extensions to Mac OS file types on PC disks" checkbox in the PC Exchange section of the File Exchange control panel.

mapping on opening files (boolean)

If set to true, Mac applications will open files based on their extension (i.e., the .htm part of index.htm), regardless of whether the file has a valid Mac file type or creator type.

PC disks mount at startup (boolean)

This is a true/false value that sets or unchecks the related checkbox at the bottom of File Exchange's PC Exchange panel.

automatic translation (boolean)

If set to true then any file you double-click in the Finder or select from a dialog box is automatically translated based on its mapping in the File Translation portion of the File Exchange control panel. This choice is the equivalent of checking or removing the check from the "Translate documents automatically" checkbox.

always shows choices (boolean)

Set this true/false value to give (or deny) the user a choice of file-translation applications when she encounters a file that is mapped to application(s) in the File Exchange control panel. For example, if this property is true, then the user is presented with a dialog box giving her a choice of opening a file with any applications that are mapped in File Exchange to that file's file type.

dialog suppress if only one (boolean)

If this property is true, then File Exchange automatically maps a file to its corresponding translator (i.e., application) as long as there is only one application mapped to the file type. In other words, it won't display the dialog of program choices to the user. This property corresponds to the "Don't show choices if there's only one" checkbox on the File Translation panel of File Exchange.

includes servers

Setting this property has the same effect as checking or unchecking its corresponding checkbox in the File Translation panel of File Exchange. Setting includes servers to true includes in any translation-choice dialog windows any relevant applications that are installed on connected servers.

PC file system enabled

The computer can read and write PC disks if this property is true.

extension mapping

This class represents the mapping of a file extension like .jpg to a Mac file type and creator type in File Exchange. This object has the following three properties:

PC extension (string)

A file extension string, as in the .jpg part of sunshine.jpg.

file type (string)

A four-character string for the file type, as in 'APPL'.

creator type (string)

A four-character string for the creator type, as in 'ToyS'. The creator type represents the program that created or owns the file; 'ToyS' is the Script Editor's creator type.

Using the File Exchange make command, you can make a new extension mapping, but alas you cannot make a new translation mapping.

translation mapping

This class or object results from the mapping in File Exchange of a file and creator type to a particular application. You cannot "make" a new translation mapping using File Exchange's make command (as you can with extension mappings), however.

file type (string)

A four-character string for the file type, as in 'TEXT'

creator type (string)

A four-character string for the creator type, as in 'ToyS'

translator application (string)

A four-character string ID for the application, as in "8BIM" (Photoshop's application signature)

translator type (string)

A four-character identifier for the translator that is used to translate the file (usually "bltn" for "built-in")

Examples

on open (alias_list)

   (* 

   alias_list is a list of aliases corresponding to the file(s) that were 

   dragged to the droplet

   *)

   set err_occurred to false (* this will be set to true if an error happens, 

then a dialog will be displayed *)

   set dropped to item 1 of alias_list (* alias of the file dropped on to the 

droplet *)

   (* 

   find out whether the file has a period in it; if it doesn't then it does not 

have a discernable extension, so return from the droplet empty handed.  

   *)

   tell application "Finder"

      if (offset of "." in (dropped as string)) = 0 then

         display dialog "The dropped file has no extension!"

         return

      end if

      (*

      get the last three characters of the file name. If there are only two 

extension characters as in ".pl" then the extension mapping will only use the 

two non-period characters anyway 

      *)

      set ext to (characters -1 thru -3 of (dropped as text)) as string

      (*

      get the file type and creator type of the dropped file and use¬

      them to make the new extension mapping

      *)

      set dropped_typ to the file type of dropped

      set dropped_cr to the creator type of dropped

   end tell

   try

      tell application "File Exchange"

         make new extension mapping with properties  {PC extension:ext,¬

         file type:dropped_typ, creator type:dropped_cr}

      end tell

   on error errmesg

      display dialog "The extension mapping failed with error " &¬

      "message: " errmesg

      set err_occurred to true

   end try

   if not err_occurred then display dialog "extension mapping succeeded!"

end open



    Team LiB   Previous Section   Next Section