#!/bin/zsh -f

thePath="$( osascript<<END
try
	tell application "Finder" to set the source_folder to (folder of the front window) as alias
on error -- no open folder windows
	set the source_folder to path to desktop folder as alias
end try

set thePath to (POSIX path of the source_folder as string)
set result to thePath
END
 )"
 


if [[ -n "${thePath%/*}" ]]; then

    if [[ -d "$thePath" ]]; then
        echo "${thePath%/}"
    else 
        echo "${thePath%/*}"
    fi
    
else 
   echo "/" 
fi 
