set config to "
the_server.type = popup
the_server.label = Please select your server.
the_server.width = 310
the_server.option = od1
the_server.option = od2
the_server.option = od3
the_server.option = od
the_server.default = od
the_user.type = textfield
the_user.label = Please enter your username.
the_user.default =
the_user.width = 340
the_pass.type = textfield
the_pass.label = Please enter your password.
the_pass.default =
the_pass.width = 340
"
-- Call Pashua and save the resulting record in pashuaResult
set pashuaResult to pashua_run(config, "", "")
activate
-- Glue code for interfacing from AppleScript to Pashua. Written by
-- Carsten Blüm <carsten@bluem.net>, 10/2003-01/2006, with improvements
-- contributed by Eddy Roosnek and Hans Haesler. You can use or modify
-- this handler any way you like in your own scripts.
-- Argument 1: Configuration string / window description
-- Argument 2: Encoding to use; if empty, Pashua assumes "macroman"
-- Argument 3: Folder that contains Pashua.app; if empty, default locations are searched
on pashua_run(config, encoding, appdir)
-- Create path for temporary file
set AppleScript's text item delimiters to ""
set tmpfile to ((path to temporary items folder as string) & "Pashua_" & (characters 3 thru end of ((random number) as string)) as string)
-- Write temporary file and fill it with the configuration string
set fhandle to open for access tmpfile with write permission
write (config as string) to fhandle
close access fhandle
-- Get temporary file's POSIX path
set posixtmpfile to POSIX path of tmpfile
set diskPath to (path to startup disk as string)
set userPath to path to "cusr" as string
set myself to (path to me as string)
tell application "Finder" to set myParentPath to (container of alias myself as string)
-- Try to find Pashua application
tell application "Finder"
-- Try to find it in the directory supplied as argument to this handler
if appdir is not "" then
if last character of appdir = ":" then
set dirsep to ""
else
set dirsep to ":"
end if
if item (appdir & dirsep & "Pashua.app") exists then
set pashua to appdir & dirsep & "Pashua.app:"
end if
-- Try to find it in this script application bundle
else if item (myself & "Contents:MacOS:Pashua") exists then
set pashua to myself
-- Try to find it in this script's parent's path
else if item (myParentPath & "Pashua.app") exists then
set pashua to (myParentPath & "Pashua.app:")
-- Try to find it in global application folder
else if item (diskPath & "Applications:Pashua.app") exists then
set pashua to (diskPath & "Applications:Pashua.app:")
-- Try to find it in user's application folder
else if item (userPath & "Applications:Pashua.app") exists then
set pashua to (userPath & "Applications:Pashua.app:")
else
display dialog "I can't find the Pashua application." & return & "It looks like Pashua is neither in one of the standard locations nor in the folder this AppleScript is in." buttons {"OK"} default button 1 with icon stop
return -1
end if
end tell
-- Append binary position inside app bundle to "regular" path
-- and convert path from HFS to POSIX representation
set pashuabinary to (POSIX path of pashua) & "Contents/MacOS/Pashua"
-- Optionally, define the encoding as command-line argument
if encoding = "" then
set encodingArg to ""
else
set encodingArg to "-e " & encoding & " "
end if
-- Execute pashua and get the string returned
set pashuaCall to "'" & pashuabinary & "' " & encodingArg & "'" & posixtmpfile & "'"
set pashuaResult to do shell script (pashuaCall)
-- Delete the temporary file
tell application "Finder" to delete tmpfile
-- Check whether the dialog was submitted at all.
-- If this is not the case, return an empty list
if pashuaResult = "" then
return {}
end if
-- Parse the result
set AppleScript's text item delimiters to return
set resultLines to text items of pashuaResult
set AppleScript's text item delimiters to ""
set recordComponents to {}
repeat with currentLine in resultLines
set eqpos to offset of "=" in currentLine
if eqpos is not 0 then
set varKey to word 1 of currentLine
try
set varValue to (text (eqpos + 1) thru end of currentLine)
-- Quote any quotation marks in varValue with a backslash.
-- The proper way to do this would be a handler, but as
-- all code for interfacing to Pashua should be as compact
-- as possible, we rather do it inline
set AppleScript's text item delimiters to "\""
set textItems to every text item of varValue
set AppleScript's text item delimiters to "\\\""
set varValue to textItems as string
set AppleScript's text item delimiters to ""
on error
set varValue to ""
end try
copy (varKey & ":\"" & varValue & "\"") to end of recordComponents
end if
end repeat
-- Return the record we read from the tmpfile
set AppleScript's text item delimiters to ", "
set resultList to (run script "return {" & (recordComponents as string) & "}")
set AppleScript's text item delimiters to {""}
return resultList
tell application "Finder"
mount volume "afp://" & the_user & ":" & the_pass & "@" & the_server & "/" & the_user
end tell
end pashua_run