#!/bin/bash

EXPORT_PATH=`defaults read com.freron.MailMate MmExportPath 2>/dev/null`
if [ ! -d "${EXPORT_PATH}" ]; then
  EXPORT_PATH="${HOME}"
fi

osascript <<END
tell application "System Events"
  activate
  set theFolder to (choose folder with prompt "Please choose a default export folder" default location (POSIX file "${EXPORT_PATH}"))
	if theFolder is not false then
		do shell script "defaults write com.freron.MailMate MmExportPath -string '" & posix path of theFolder & "'"
		return posix path of theFolder
	end if
  return ""
end tell
END
