Skip to content

Add validation that Invoke-Item opens directory in Finder on Mac #4282

Closed

Description

For PR #4262 validation was added to Windows and Linux.
On Linux, we change the default application to a shell command to verify the output. On Mac, you would
use lsregister to do something similar, however, MacOS doesn't have a straightforward way to register
and unregister at runtime (no api). Registration is done as part of app creation and startup.

Activity

  1. added
    WG-Quality-Test
    on Jul 18, 2017
  2. mklement0 commented on Jul 18, 2017

    @mklement0
    Contributor

    You can use AppleScript as follows (via its osascript CLI):

    $appleScriptWindowCount = 'tell application "Finder" to count of windows'
    
    $before = [int] ($appleScriptWindowCount | osascript)
    
    Invoke-Item $PSHome
    
    $startTime = Get-Date
    while (((Get-Date) - $startTime).TotalSeconds -lt 5 -and ([int] ($appleScriptWindowCount | osascript) -eq $before))
    {
      Start-Sleep -Milliseconds 100
    }
    
    $after = [int] ($appleScriptWindowCount | osascript)
    
    $before + 1  | Should Be $after
    
    ('tell application "Finder" to POSIX path of ((target of front window) as text)' | osascript) | Should Be "$PSHOME/"
    
    'tell application "Finder" to close front window' | osascript

    Note the need to pipe the AppleScript source code to osascript, because argument passing on Unix is still horribly broken (I've lost track of the debate):

    osascript -e 'tell application "Finder" to count of windows'

    SHOULD work, but currently doesn't, because the embedded " are discarded.

    Remember: On Unix, no funny quoting business (no rebuilding of the command line) is needed nor should it be attempted after PowerShell has parsed a command line; the resulting values should be passed as literals, as part of an argument array to the target utility.

  3. SteveL-MSFT commented on Jul 25, 2017

    @SteveL-MSFT
    MemberAuthor

    Michael Klement (@mklement0) got around to finishing this. your pointer to AppleScript really helped!

  4. mklement0 commented on Jul 26, 2017

    @mklement0
    Contributor

    Steve Lee (@SteveL-MSFT): I am glad to hear it.

    Ceterum censeo argumentum transitum esse reficiendam.[1]

    [1] That's fake Latin for: Fix the argument passing on Unix platforms.

  5. SteveL-MSFT commented on Jul 26, 2017

    @SteveL-MSFT
    MemberAuthor

    If there isn't an issue already, please open one for that

  6. mklement0 commented on Aug 28, 2017

    @mklement0
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-macOSResolution-FixedWG-Quality-Test

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions