Monday, March 5, 2012

Qt Creator On Mac, Asking For Password

Qt Creator may ask for a password, if automatic login is not configured for the version control system. The Linux utility for this task is usually ssh-askpass, but it does not exist on the Mac.

Here is an alternative, originating from Joseph Mocker:


#! /bin/sh
# An SSH_ASKPASS command for MacOS X, with minor modifications to macos-askpass
# by Joseph Mocker, Sun Microsystems.
#
# To use this script:
#     setenv SSH_ASKPASS "ssh-askpass-mac"


TITLE="Enter SSH Password"  
DIALOG="display dialog \"$@\" default answer \"\" with title \"$TITLE\""
DIALOG="$DIALOG with icon 1 with hidden answer"  


result=`osascript -e 'tell application "Finder"' -e "activate"  -e "$DIALOG" -e 'end tell'`  


if [ "$result" = "" ]; then
    exit 1
else
    echo "$result" | sed -e 's/^text returned://' -e 's/, button returned:.*$//'
    exit 0
fi

Save it to /usr/local/bin/ssh-askpass-mac, and let Qt Creator know where to find: PreferencesVersion ControlSSH prompt command.

1 comment:

  1. On my OS X Sierra (10.2) this did not work anymore, as the return output (button returned / text returned) was switched. So I adapted the script a little. Works now perfectly for me. Thanks!

    #! /bin/sh
    # An SSH_ASKPASS command for MacOS X, with minor modifications to macos-askpass
    # by Joseph Mocker, Sun Microsystems.
    #
    # To use this script:
    # setenv SSH_ASKPASS "ssh-askpass-mac"


    TITLE="Enter SSH Password"
    DIALOG="display dialog \"$@\" default answer \"\" with title \"$TITLE\""
    DIALOG="$DIALOG with icon 1 with hidden answer"


    result=`osascript -e 'tell application "Finder"' -e "activate" -e "$DIALOG" -e 'end tell'`


    if [ "$result" = "" ]; then
    exit 1
    else
    echo "$result" | sed -e 's/^button returned:OK//' -e 's/, text returned://'
    exit 0
    fi

    ReplyDelete