AppleScript Types

From Quicksilver Wiki
Jump to: navigation, search

Contents

[edit] Overview

This page lists the supported types that can be used in an AppleScript's get direct types and get indirect types routines.

get direct types Use this handler to return a list of valid object types for which your AppleScript action will appear

get indirect types Use this handler to return a list of valid types that you want to appear in the 3rd pane for your AppleScript action. Note that for the 3rd pane to appear for an AppleScript action, you must implement the get argument count handler. See the AppleScript Actions page for more information.

[edit] Object Types

Type Description
"NSFilenamesPboardType" Files and folders
"NSStringPboardType" Text or a string
"Apple URL pasteboard type" URLs
"QSFormulaType" Formulas as used by the Calculator Plugin
"qs.process" Running applications or processes
"qs.command" Quicksilver command
"QSRemoteHostsType" Remote hosts (from the Remote Hosts Plugin)
"com.apple.itunes.track" iTunes tracks (indexed by the iTunes Plugin)
"ABPeopleUIDsPboardType" Address Book / Contacts.app contacts (requires plugin?)

[edit] Examples

[edit] Specify the objects for which an action displays

If you would only like a certain AppleScript action to display for URLs and Text, you would add the following code to your AppleScript:

on get direct types
     return {"Apple URL pasteboard type", "NSStringPboardType"}
end get direct types

[edit] Specify the 3rd pane object types

For a given AppleScript action, if you only want files to appear in the 3rd pane, you would use the following code:

on get indirect types
    return {"NSFilenamesPboardType"}
end get indirect types

Note that the difference between this and the first example is the use of indirect as opposed to direct

[edit] A real live example

A handy AppleScript for creating short URLs can be found on the Shorten URL (AppleScript) page. It makes sense to only have this action available for URL objects, instead of all text objects (which is the default for the on process text handler. In order to achieve this, you would modify the (first) script to be as follows:

using terms from application "Quicksilver"
        on get direct types
                return {"Apple URL pasteboard type"}
        end get direct types

        on process text theURL
                set shortURL to do shell script "curl -s https://www.googleapis.com/urlshortener/v1/url -H 'Content-Type: application/json' -d \"{\\\"longUrl\\\": \\\"" & theURL & "\\\"}\" | awk '/\"id\":/{print substr($2, 2, length($2)-3)}'"
                return shortURL
        end process text
end using terms from