FinderSelection Reference

FinderSelection is an AppleScriptLibrary to obtain items meeting specified conditions from selected items in Finder.

By using FinderSelection, following complex sequence can be easily performed with several lines.

  1. Obtain Finder's selection filterd with conditions of specified kind, file type or path extension.
  2. If items matched with the conditions did not exist, a panel to select files will be opened.
  3. In the case of you script is an applet or a droplet and the application is launched with double clicking in Finder, a panel to select files will be opened.
  4. If alias files are included in selected items, the originals are checked with the conditions.
    • The behaivior can be changed to prevent following originals at setting.

Actual sequence of code is as follows.

  1. Generate an instance of FinderSelection by Constructor methods. Choose Constructor depending on kind of files and folders you want.
  2. Set a message displayed in the open panel by set_prompt_message.
    • The open panel will apear when thre are not items matched with the conditions.
  3. URI, file tyepe and path extension can be included in the conditions by set_types, set_extensions.
    • When both of set_types and set_extensions are set, target items will match with either file type or path extension.
  4. By get_selection, you can take a list of items matched with the conditions

The following script is a sample to obtain text files and PDF files from Finder's selection.

use FinderSelection : script "FinderSelection"

set file_picker to FinderSelection's make_for_file()

tell file_picker
set_prompt_message("Choose text file or PDF file.")
set_types({"com.apple.traditional-mac-plain-text", "TEXT", "PDF "})
set_extensions({".txt", ".pdf"})
get_selection()
end tell

Constructors

Generate an instance depending on kind of items you want from Finder's selection

make_for_item

Genegate an instance to obtain all of selected files and folders in Finder.

make_for_file

Generate an instance to pick up files from selection in Finder.

make_for_document

Generate an instance to pick up documents from selection in Finder.

make_for_application

Generate an instance to pick up applications from selection in Finder.

make_for_package

Generate an instance to pick up packages from selection in Finder.

make_for_container

Generate an instance to pick up disks or folders from selection in Finder.

make_for_folder

Generate an instance to pick up folders from selection in Finder.

make_for_disk

Generate an instance to pick up disks from selection in Finder.

Getting Finder's Selection

get_selection

Obtain Finder's selection as a list.

is_insertion_location

Return whether an item returned by get_selection is Finder's insertion location or not.

Accessor Methods

You can customize behaivior of an instance of FinderSlection.Following three mehods will be frequently used.

set_types

set UTIs or file types of items you want.

set_extensions

Set path extensions of items you want.

set_prompt_message

Set a message to displayed in open panel.

set_use_chooser

Whether open panel will be opened or not when threre are not items matched with the conditions in selection in Finder.

set_use_insertion_location

Whether insertion location is obtained as a selected item or not, when no items are selected in Finder.

set_allow_myself

If my self(a script or an application running FinderSelection) is selected in Finder, whether my selft is treated as a member of selection or not.

set_resolve_alias

Whether original of alias is searched for or not.

set_default_location

The default location of the open panel which is displayed when no items are selected in Finder.

Setup Kind Items to Pick Up

Change settings of kinds of file and folder to find for instance.Usually these methods are not required, because these methods are called in constructor methods.

These methods are useful to change settings of an instastance after generating an instance.

setup_for_item

Make all files and folders targets.

setup_for_file

Make only files targets.

setup_for_document

Make only document files targets.

setup_for_application

Make only applications targets.

setup_for_package

Make only packages targets.

setup_for_container

Make containers (disks and folders) targets.

setup_for_folder

Make only folders targets.

setup_for_disk

Make only disks targets.

Utility Handlers

is_same_to_me

Whether the passed item is identical to the result of "e;path to me"e; or "e;path to current application"e;.