5

I'm attempting to build an Automator workflow (which will be saved as a Service, so that I can both access it from contextual menus and invoke it with a keyboard shortcut), that will function much like the Finder's built-in "Show Package Contents" command, but which will additionally accept a package's alias as input. The service will satisfy the following:

It will only be available when the Finder's selection consists of a package or a package's alias.

Rather than show the contents of the package directory itself like the built-in command does, the Service will show the contents of the "Contents" directory (if it exists), located immediately within the package directory.

If the Finder's selection is a package or alias on the desktop, the Contents directory should be opened in a new Finder window. Otherwise, the Contents directory should be opened in the Finder window containing the selection.

My approach has been to have the script first determine whether the file is an Alias, and if it is, to tell the script to show the contents of the original. If the file is not an alias, I'd like to tell the script to simply show the contents of the input.

Excluding the possibility of an alias as input and assuming the input-package is selected in a Finder window, I can successfully write a script that shows the contents of the package's contents folder in the same window:

on run {input, parameters}
    set my_output to {}
    repeat with oneItem in input
        tell application "Finder" to set target of window 1 to ((oneItem as text) & "Contents")
end repeat
return input
end run

When I try to set up an "if...then...else" scheme, I fail.

I'm using the latest versions of all relevant software.

  • Welcome, we are not ignoring you, just waiting for someone who can answer your question. – Ruskes Apr 2 '14 at 12:04
  • Please can you append a failing, if/then/else, attempt. Debugging why this is failing will likely lead to a faster solution for you. – Graham Miln Apr 2 '14 at 13:29
1

folder "Contents" of also works with aliases:

on run {input, parameters}
    tell application "Finder"
        repeat with f in input
            open folder "Contents" of f
        end repeat
    end tell
end run

You can also assign a shortcut for showing package contents from System Preferences:

Command-R shows the original file of an alias.

1

You can try something like this:

   on run {input, parameters}
    tell application "Finder"
        repeat with oneItem in input
            if kind of oneItem = "Alias" then set oneItem to oneItem's original item
            set contentsPath to (oneItem as text) & "Contents"
            if oneItem's container as text = (path to desktop as text) then
                open contentsPath
            else
                set target of window 1 to contentsPath
            end if
            activate
        end repeat
    end tell
end run

You may also want to include a test to make sure the input is the expected type.

  • This workflow fails: "Run AppleScript failed - 1 error: AppleEvent handler failed." – Parker Apr 2 '14 at 16:28
  • There was an extra colon. Try again. – adayzdone Apr 2 '14 at 19:37
0

I got it:

on run {input, parameters}
    tell application "Finder"
        repeat with f in input
            reveal f
            set target of window 1 to (folder "Contents" of f as text)
        end repeat
    end tell
end run

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .