-- Self-contained WPMacApp SheepShaver setup  

-- Version 5.79- 17 December 2011

-- Script by Edward Mendelson http://wpdos.org

-- Based on ideas by John Rethorst

-- Applet includes work by Smokey Ardisson

-- to do: add document size screen option: 640 width, 742 height


-- DEFAULT SCREEN SIZE 896 x 672

-- feel free to change these settings from 896 x 672

property defaultWidth : 896

property defaultHeight : 672


-- USE DEFAULT SCREEN SIZE OR CALCULATE PORTRAIT OR LANDSCAPE SIZE

-- the default WPMacApp appliance size is 896 x 672; however,

--   if you want the WPMacApp appliance screen size to be calculated

--   as a proportion of your Mac's screen size, change 0 to 1 or 2 below

-- for a calculated landscape-style layout, change 0 to 1

-- for a calculated portrait-style layout, change 0 to 2

property calculateSize : 0


-- to specify window size permanently, use the SheepShaver Preferences dialog;

-- to make a portrait-layout window that WP can fill, use width 640, height 720 (or up to 742)


-- Next section is NOT yet implemented

-- USE DOCUMENT-SIZED SCREEN SIZE 640 X 742

-- property documentWidth : 640

-- property documentHeight : 742


-- USE HOME FOLDER (NOT USER/DOCUMENTS) AS "UNIX" FOLDER

-- by default, this script uses the user's Documents folder as the

--   SheepShaver "Unix" folder; you may prefer to use your

--   Home folder instead, although this may cause problems for 

--   other AppleScripts; to use Home, change 0 to 1 below

property useHomeFolder : 0


-- ENABLE DIRECT PRINTING TO LOCAL PRINTER

-- use this option to make it possible to use a local printer

--   directly, without setting up the special print system.

-- To disable direct printing to a local printer, set to 0

property enableLocalPtr : 1


-- the following lines are for debugging only; do not change them!

-------------------------------------------------------------

-- SETUP OLD PRINTING SYSTEM

property doOldPrintSystem : 0

property doSystemSetup : 0

-- DO NOT PROMPT FOR PRINTERS

-- to suppress the prompt asking to setup a printer, change to 1

property suppressPrinterPrompt : 0


-- never change anything below these lines!

-------------------------------------------------------------

-------------------------------------------------------------


property msgTitle : "WPMac Appliance Launcher"

property reqVers : 5


global forceFullScreen, defaultScreenSize


global sheepApp, sheepPath, filesFolder, macSystem, macPath

global userPath, unixPosixPath, userLibPath, userPosixPath, unixPath

global vertBound, horizBound, maxHeight, maxWidth, fullScreen

global UNIX_plist_path, presMode, ssRunning, questionIcon

global thisApp, checkKeysPosix, myUnix, vmPath, vmPosix

global extfsPath, useSelectedUnix

-------------------------------------------------------------

-- variables for installing printing system:

global userLibScrPath, userFldrPath, thisApp, otherUnix

global printAction, neverFile, doPrompt, doSetup, sysAbsent

-------------------------------------------------------------

-- variables for Spotlight and QuickLook plugins

global sysVers, Leopard

-------------------------------------------------------------

-- variables for dropped items

global unixFolder, posixFolder, actionChoice, runCount

global fileOnlyName, thePosPath, nameCount, aliasForList

-------------------------------------------------------------

-- variables for printer and CUPS-PDF installation

global cupsPkg, cupsPkgPath, doPrinterSetup, doCupsSetup

global setupDoneOnce, fileNotNow, thePrinter, theQueue, ptrButton


-------------------------------------------------------------

-- run and open

on run

doBasics()

runVM()

removePrintSystem()

error number -128

end run


on open (filesToOpen)

doBasics()

transferData(filesToOpen)

runVM()

removePrintSystem()

error number -128

end open


-------------------------------------------------------------

-- shared routines


on doBasics()

-- USE QUASI-FULLSCREEN MODE

-- to make SheepShaver Wrapper run in a quasi-fullscreen mode, use the SheepShaver

--  preferences dialog and set mode to fullscreen, not window

--   or, in preferences, set both height and width to 0

--   alternatively, to force fullscreen mode, change 0 to 1 below

--   or hold down Command key when launching this application

-- Warning: this option hides the dock and menu bar when this app runs

-- NOTE THAT SETTING "forceFullScreen : 1" OVERRIDES "calculateSize : 1 or 2"

set forceFullScreen to 0

-- RESTORE DEFAULT SCREEN SIZE 896 x 672

-- to restore default screen size change 0 to 1

-- or hold down Option key when launching this application

set defaultScreenSize to 0

set doPrinterSetup to 0

set doCupsSetup to 0

set setupDoneOnce to 0

set fileNotNow to 0

set thePrinter to ""

set theQueue to ""

set ptrButton to ""

checkHostSystem()

screenDimension()

getMyName()

setupPaths()

writePrefs()

addPlugins()

setDataFolder()

allPrintRoutines()

end doBasics


-------------------------------------------------------------

-- starting subroutines


-- not used yet

on processRunning(processName)

return (do shell script "ps axc") contains processName

end processRunning


on checkHostSystem()

-- Running on Leopard or later?

set Leopard to 0

set sysVers to ((system attribute "sysv") mod 4096 div 16)

if sysVers < reqVers then

set dialogText to "This application runs under OS X 10." & reqVers & " or later, and you seem to have an earlier version of OS X."

errorQuit(dialogText)

end if

if sysVers is 5 then set Leopard to 1

-- is SheepShaver already running?

set ssRunning to false

if application "WPMacApp" is running then

tell application "System Events"

set apps to every process whose bundle identifier is "org.wpdos.wpmacapp.sheepshaver"

if not (apps is {}) then

set ssRunning to true

end if

end tell

end if

end checkHostSystem


on screenDimension()

-- change screen dimension, check for Cmd or Option key down, to set or unset full-screen

-- and force printer installation

set thisApp to path to me as text

set checkKeysPath to (thisApp & "Contents:Resources:Files:checkModifierKeys")

set checkKeysPosix to quoted form of (POSIX path of checkKeysPath)

set cmdState to do shell script checkKeysPosix & space & "cmd"

set optionState to do shell script checkKeysPosix & space & "option"

set cmdOptionState to do shell script checkKeysPosix & space & "cmd option"

set capsState to do shell script checkKeysPosix & space & "capslock"

-- CapsLock on means go to setup menu

if capsState is "1" then

repeat while capsState is "1"

tell me to activate

display dialog "Please turn off Caps Lock before proceeding." buttons {"OK"} default button 1 with title msgTitle

set capsState to "0"

set capsState to do shell script checkKeysPosix & space & "capslock"

end repeat

set extraString to return & return & "This menu appears if CapsLock is ON when the application starts."

my askforUnix(extraString)

end if

-- both Cmd and Option mean set up a printer

if cmdOptionState is "1" then

my printerPrompt()

else

-- Cmd down means go to quasi-full-screen

if cmdState is "1" then

tell me to activate

display dialog "Set the WPMacApp to open in a quasi-full-screen mode?" & return & return & "(This message appears because you held down the Command key while starting the application.)" & return & return & "If you click OK to set quasi-full-screen mode, you can return to ordinary windowed mode by holding down the Option key the next time you start the application." buttons {"OK", "Cancel"} default button 1 with title msgTitle

if button returned of the result is "Cancel" then

error number -128

else

tell application "System Events"

if UI elements enabled then

else

my setupUniversalAccess()

end if

end tell

-- if forceFullScreen is 0 then

set forceFullScreen to 1

-- else

-- set forceFullScreen to 0

-- end if

end if

end if

-- Option down means switch back to default size

if optionState is "1" then

tell me to activate

display dialog "Set the WPMacApp to open in ordinary windowed mode?" & return & return & "(This message appears because you held down the Option key while starting the application.)" & return & return & "You may switch to a quasi-full-screen mode by holding down the Command key the next time you start the application." buttons {"OK", "Cancel"} default button 1 with title msgTitle

if button returned of the result is "Cancel" then

error number -128

end if

tell application "System Events"

if UI elements enabled then

else

my setupUniversalAccess()

end if

end tell

set forceFullScreen to 0

set defaultScreenSize to 1

end if

end if

if ssRunning is false then

set horizBound to 0

set vertBound to 0

-- routines to set screen size

set dspsizes to getDspSizes()

set widthList to {}

set heightList to {}

repeat with thisItem in dspsizes

set the end of widthList to first item in thisItem as number

set the end of heightList to second item in thisItem as number

end repeat

set sortedWidths to simple_sort(widthList)

set sortedHeights to simple_sort(heightList)

set maxWidth to the first item in sortedWidths as number

set maxHeight to the first item in sortedHeights as number

if calculateSize = 1 then

set horizBound to round maxHeight * 1.12

if horizBound is greater than 1600 then

set horizBound to 1600

else if horizBound is greater than 1280 then

set horizBound to 1280

else if horizBound is greater than 1152 then

set horizBound to 1152

end if

set vertBound to round horizBound * 0.75

set vertBound to vertBound as string

set horizBound to horizBound as string

else if calculateSize = 2 then

set horizBound to round maxHeight * 0.8

if horizBound is greater than 1600 then

set horizBound to 1600

else if horizBound is greater than 1280 then

set horizBound to 1280

else if horizBound is greater than 1152 then

set horizBound to 1152

end if

set vertBound to round horizBound * 1.125

set vertBound to vertBound as string

set horizBound to horizBound as string

end if

end if

end screenDimension


on setupPaths()

set useSelectedUnix to 1

try

do shell script "ls " & quoted form of extfsPath

on error

set useSelectedUnix to 0

end try

-- use Home or Documents folder?

if useHomeFolder = 1 then

set otherUnix to path to documents folder as text

else

set otherUnix to path to home folder as text

end if

if useSelectedUnix = 1 then

my setUnixFolder()

else

if useHomeFolder = 1 then

set unixPosixPath to POSIX path of (path to home folder)

set unixPath to path to home folder as text

-- set otherUnix to path to documents folder as text

else

set unixPosixPath to POSIX path of (path to documents folder)

set unixPath to path to documents folder as text

-- set otherUnix to path to home folder as text

end if

end if

set userPath to path to home folder as text

set userLibPath to path to library folder from user domain as text

-- Set up paths in this app

set sheepApp to (path to me) & "Contents:Resources:Files:SheepShaver.app" as string

set sheepApp to sheepApp as alias

set sheepPath to (POSIX path of sheepApp)

try

set macSystem to (path to me) & "Contents:Resources:Files:MacOS.sheepvm" as string

set macSystem to macSystem as alias

set macPath to (POSIX path of macSystem)

on error

tell me to activate

set dialogText to "Add a self-contained sheepvm named MacOS.sheepvm to this application, in the folder Contents:Resources:Files."

errorQuit(dialogText)

end try

set questionIcon to ((path to me as text) & "Contents:Resources:Files:Question.icns") as alias

if Leopard is 1 then

set cupsPkg to (path to me) & "Contents:Resources:Files:CUPS-PDF-Leopard.pkg" as string

else

set cupsPkg to (path to me) & "Contents:Resources:Files:CUPS-PDF.mpkg" as string

end if

set cupsPkg to cupsPkg as alias

set cupsPkgPath to (POSIX path of cupsPkg)

end setupPaths


on setUnixFolder()

set vmPath to (path to me) & "Contents:Resources:Files:MacOS.sheepvm" as string

set vmFile to vmPath as alias

set vmPosix to (POSIX path of vmFile) as string

-- set extfsPosix to (vmPosix & "extfsposix")

set extfsPath to (vmPosix & "extfspath")

set unixPath to paragraph 1 of (read POSIX file extfsPath)

set unixPosixPath to POSIX path of file unixPath

if useHomeFolder = 1 then

set otherUnix to path to home folder as text

else

set otherUnix to path to documents folder as text

end if

end setUnixFolder


on writePrefs()

if ssRunning is false then

set prefsFile to (path to me) & "Contents:Resources:Files:MacOS.sheepvm:prefs" as string

set prefsFile to prefsFile as alias

set prefsPath to (POSIX path of prefsFile) as string

set savePath to ((POSIX path of prefsFile) & ".storage")

set tempPath to ((POSIX path of prefsFile) & ".tempfile")

set screenPath to ((POSIX path of prefsFile) & ".screen")

-- write prefs file

-- first backup prefs

try

do shell script "cp " & quoted form of prefsPath & " " & quoted form of savePath

on error

set dialogText to "Problem backing up preferences file. No changes made."

end try

--  remove existing data before replacing

try

if (calculateSize is greater than 0) or (defaultScreenSize is greater than 0) then

do shell script "grep -v '^extfs\\|^screen' " & quoted form of prefsPath & " > " & quoted form of tempPath

else

do shell script "grep -v '^extfs' " & quoted form of prefsPath & " > " & quoted form of tempPath

end if

on error

set dialogText to "Problem extracting data from preference file. No changes made."

errorQuit(dialogText)

end try

--  insert replaced data

try

do shell script "echo extfs " & quoted form of unixPosixPath & ">> " & quoted form of tempPath

if defaultScreenSize is greater than 0 then

copy defaultWidth to horizBound

copy defaultHeight to vertBound

end if

if (calculateSize is greater than 0) or (defaultScreenSize is greater than 0) then

do shell script "echo screen win/" & horizBound & "/" & vertBound & " >> " & quoted form of tempPath

end if

on error

set dialogText to "Problem reading data from preference file. No changes made."

errorQuit(dialogText)

end try

try

do shell script "mv " & quoted form of tempPath & " " & quoted form of prefsPath

on error

set dialogText to "Problem creating new preferences file. No changes made."

errorQuit(dialogText)

end try

try

do shell script "rm " & quoted form of savePath

end try

-- routine for full-screen option

set fullScreen to 0

if forceFullScreen = 1 then

set fullScreen to 1

end if

set fullWidth to maxWidth as string

set fullHeight to maxHeight - 21 as string

set fullNumbers to fullWidth & "/" & fullHeight

-- did user specify "fullscreen" or 0/0 dimensions in SheepShaver prefs?

if fullScreen = 0 then

try

set fullByPrefs to true

set fullScreen to do shell script "grep -c 'dga/\\|/0/0' " & quoted form of prefsPath

on error

set fullByPrefs to false

end try

--

try

set fullByPrevious to true

set fullScreen to do shell script "grep -c '" & fullNumbers & "' " & quoted form of prefsPath

on error

set fullByPrevious to false

end try

if fullByPrefs is true then set fullScreen to 1

if fullByPrevious is true then set fullScreen to 1

end if

if fullScreen is greater than 0 then

-- set SheepShaver size to width of Mac by height minus menu line

-- set fullWidth to maxWidth as string

-- set fullHeight to maxHeight - 21 as string

try

do shell script "cp " & quoted form of prefsPath & " " & quoted form of savePath

on error

set dialogText to "Problem backing up preferences file. No changes made."

end try

try

do shell script "grep -v '^screen' " & quoted form of prefsPath & " > " & quoted form of tempPath

on error

set dialogText to "Problem reading screen size from preference file. No changes made."

errorQuit(dialogText)

end try

try

do shell script "echo screen win/" & fullWidth & "/" & fullHeight & " >> " & quoted form of tempPath

end try

try

do shell script "mv " & quoted form of tempPath & " " & quoted form of prefsPath

on error

set dialogText to "Problem writing new preferences file. No changes made."

errorQuit(dialogText)

end try

try

do shell script "rm " & quoted form of savePath

end try

-- modify info.plist so dock disapepars

set presMode to "LSUIPresentationMode"

set Mac_plist_path to (sheepPath as string) & "Contents/"

-- display dialog Mac_plist_path

tell application "Finder"

set plistFile to (Mac_plist_path & "info.plist")

if not (exists (file (Mac_plist_path & "original.plist"))) then

try

do shell script "cp " & quoted form of POSIX path of plistFile & space & quoted form of POSIX path of (Mac_plist_path & "original.plist")

on error

tell me to activate

display dialog "Problem here."

end try

end if

end tell

set UNIX_plist_path to quoted form of POSIX path of (Mac_plist_path & "info")

set script_text to "defaults write " & UNIX_plist_path & space & presMode & space & "-int" & space & "4"

try

do shell script script_text

on error

set script_text to "defaults write " & UNIX_plist_path & space & presMode & space & "-int" & space & "1"

try

do shell script script_text

on error

tell me to activate

display dialog "Error writing SheepShaver defaults for WPMacApp." buttons {"OK"} default button 1 with icon stop giving up after 5

end try

end try

end if

end if

end writePrefs


on runVM()

-- now to run the program

if ssRunning is true then

do shell script "open -a" & space & quoted form of sheepPath

else

do shell script "open -a" & space & quoted form of sheepPath & space & quoted form of macPath

-- if full screen, nudge window to top of screen

if fullScreen is greater than 0 then

tell application "System Events"

repeat until (process "SheepShaver" exists)

delay 0.1

end repeat

tell process "SheepShaver"

repeat until window 1 exists

delay 0.1

end repeat

end tell

delay 0.7

tell process "SheepShaver"

tell window 1

set position to {0, 0}

end tell

end tell

end tell

delay 0.5

-- restore original info.plist settings

set script_text to "defaults write " & UNIX_plist_path & space & presMode & space & "-int" & space & "1"

try

do shell script script_text

--display dialog "Set SheepShaver to hide dock." with icon caution giving up after 5

on error

tell me to activate

display dialog "Error writing SheepShaver defaults for WPMacApp." buttons {"OK"} default button 1 with icon stop giving up after 5

end try

end if

end if

end runVM


-------------------------------------------------------------

-- subroutines 


on setDataFolder()

-- this creates .WPTransfer folder for communicating between OS X and SheepShaver

set unixFolder to ""

set text item delimiters to "/"

set posixItems to text items 2 thru -1 of unixPosixPath

set text item delimiters to ":"

set partialPath to (posixItems as string)

set unixFolder to (path to startup disk as string) & text 1 thru -1 of partialPath

set posixFolder to unixPosixPath & ".WPTransfer"

try

do shell script "ls -a " & quoted form of (posixFolder)

set folderFound to true

on error

set folderFound to false

end try

if folderFound is false then

do shell script "mkdir " & quoted form of posixFolder

end if

-- delete stray printer queue information file

try

do shell script "rm " & quoted form of (posixFolder & "/QueueName.txt")

end try

-- test for printer setup done file

if doPrinterSetup is 0 then

try

do shell script "ls -a " & quoted form of (posixFolder & "/SetupDone")

set setupDoneOnce to 1

on error

try

do shell script "ls -a " & quoted form of (posixFolder & "/NeverAsk")

on error

my printerPrompt()

end try

end try

end if

-- test for setup CUPS alias file

set makeAlias to 0

if doPrinterSetup is 0 then

try

do shell script "ls -a " & quoted form of (posixFolder & "/MakeCupsAlias")

set makeAlias to 1

on error

set makeAlias to 0

end try

if makeAlias is 1 then

try

do shell script "rm " & quoted form of (posixFolder & "/MakeCupsAlias")

end try

my makeCupsShortcut()

end if

end if

-- test for Print or Make PDF in OSX setup

if doPrinterSetup is 0 then

try

do shell script "ls -a " & quoted form of (posixFolder & "/DoFolderSetup")

set doSystemSetup to 1

on error

set doSystemSetup to 0

end try

if doSystemSetup is 1 then

try

do shell script "rm " & quoted form of (posixFolder & "/DoFolderSetup")

end try

my makePrintSystem()

end if

end if

end setDataFolder


on allPrintRoutines()

-- gather all the print option tests in one place

if doOldPrintSystem is 1 then

my makePrintSystem()

end if

if enableLocalPtr is 1 then

my localPrinter()

end if

if doPrinterSetup is 1 then

set doCupsSetup to 0

my setupPrinter()

end if

if doCupsSetup is 1 then

set doPrinterSetup to 0

my setupCups()

end if

end allPrintRoutines


on transferData(filesToOpen)

set fileCount to count of filesToOpen

----

set unixFolderCharCount to (count characters of unixFolder)

set fileList to ""

repeat with i in filesToOpen

set i to i as string

if not (i contains unixFolder) then

tell application "Finder" to set thisPosixName to POSIX path of (i as alias)

tell me to activate

display dialog "The file “" & thisPosixName & "” is not in the folder “" & unixPosixPath & "”, which corresponds to the “Unix” folder in the WPMacApp)." & return & return & "It is therefore inaccessible to the WPMacApp." & return & return & "Please move the file into your folder “" & unixPosixPath & "”, and select it again." buttons {"OK"} default button 1 with icon caution with title msgTitle

error number -128

else

set thePosPath to POSIX path of i

set fileOnlyName to do shell script "basename " & quoted form of thePosPath

set nameCount to (count characters of fileOnlyName)

if nameCount is less than 32 then

else

if ssRunning is false then

if fileCount is greater than 1 then

set dlgButtons to {"OK"}

else

set dlgButtons to {"Open the WPMacApp", "Cancel"}

end if

else

set dlgButtons to {"OK"}

end if

-- this tests for filename too long for OS 9

set runCount to 0

set aliasForList to ""

bigName()

copy aliasForList to i

set i to i as string

end if

-----

set iCount to (count characters of i)

if iCount is greater than 0 then

set netPath to text (unixFolderCharCount + 1) thru iCount of i

if netPath starts with ":" then

else

set netPath to ":" & netPath

end if

set unixPath to "Unix" & netPath -- removed ":" after Unix

set fileList to fileList & unixPath & return

end if

end if

end repeat

do shell script "echo " & quoted form of fileList & " >> " & quoted form of (posixFolder & "/wpFileList")

quit

end transferData


-------------------------------------------------------------

-- subroutines for setting up old printing system


on makePrintSystem()

testForPrompt()

if doPrompt is "yes" then

systemExists()

if sysAbsent = "yes" then

askToSetup()

if doSetup = "yes" then

setupPrintSys()

end if

end if

end if

end makePrintSystem


on testForPrompt()

set doPrompt to "no"

-- test whether to do the setup at all

set neverFile to "DeleteThisToRestoreSetupPrompt.txt"

set noPrompt to (path to me as text) & "Contents:Resources:Files:DeleteThisToRestoreSetupPrompt.txt"

-- set noPrompt to (filesFolder & neverFile) as text

try

set noPrompt to noPrompt as alias

on error

set doPrompt to "yes"

end try

end testForPrompt


on systemExists()

set sysAbsent to "no"

set printPath to (unixPath & "Folder for PrintFiles") as text

try

set printAlias to printPath as alias

on error

set sysAbsent to "yes"

end try

set userLibScrPath to path to scripts folder from user domain

try

set userLibScrAlias to userLibScrPath as alias

on error

set sysAbsent to "yes"

end try

set userFldrPath to path to Folder Action scripts

try

set userFldrAlias to userFldrPath as alias

on error

set sysAbsent to "yes"

end try

set actionScript to (userFldrPath & "PrintOrPDFWPMac.scpt") as text

try

set actionAlias to actionScript as alias

on error

set sysAbsent to "yes"

end try

return sysAbsent

end systemExists


on askToSetup()

try

do shell script "mkdir ~/Library/Scripts"

end try

try

do shell script "mkdir ~/Library/Scripts/" & quote & "Folder Action Scripts" & quote

end try

set userLibScrPath to path to scripts folder from user domain with folder creation

set userFldrPath to path to Folder Action scripts with folder creation

set thisApp to path to me as text

set filesFolder to (thisApp & "Contents:Resources:Files:") as text

set filesFolder to filesFolder as alias

set printAction to (thisApp & "Contents:Resources:Files:PrintOrPDFWPMac.scpt") as text

set printAction to printAction as alias

-- ask whether to proceed?

set dialogText to "I will now setup the OS X elements of a system that creates PDF files from WordPerfect or prints from WordPerfect to the default OS X printer. I only need to perform this setup once." & return & return & "This system is required if you use the “Print or Make PDF in OS X” printer in WordPerfect, and you must run (or already have run) the “SETUP Print or Make PDF in OS X” script in the Virtual Printers folder in the WPMacApp." & return & return & "Shall I proceed?"

tell me to activate

display dialog dialogText buttons {"Yes", "No, but ask next time", "No, never ask again"} default button 1 with icon caution with title msgTitle

set userChoice to button returned of result

if userChoice = "Yes" then

set doSetup to "yes"

end if

if userChoice = "No, but ask next time" then

set doSetup to "no"

end if

if userChoice = "No, never ask again" then

set doSetup to "never"

do shell script "echo DoNotPrompt > " & (quoted form of POSIX path of filesFolder) & neverFile

set dialogText to "An 'Install WPMac Print System' installer script can be copied to your home folder so that you can install the PDF and Printing System at a later time." & return & return & "Copy this script to your home folder?"

tell me to activate

display dialog dialogText buttons {"Yes", "No"} default button 1 with icon questionIcon with title msgTitle

set userChoice to button returned of result

if userChoice = "Yes" then

tell application "Finder"

set installerApp to (thisApp & "Contents:Resources:Files:Install WPMac Print System.app") as text

set installerApp to installerApp as alias

duplicate installerApp to userPath with replacing

end tell

end if

end if

return doSetup

end askToSetup


on setupPrintSys()

-- install output folder, copy script file

do shell script "/bin/mkdir -p " & quoted form of POSIX path of (unixPath & "Folder for PrintFiles")

set printPath to (unixPath & "Folder for PrintFiles")

do shell script "/bin/cp " & quoted form of POSIX path of printAction & space & quoted form of POSIX path of userFldrPath

set actionScript to (userFldrPath as text) & "PrintOrPDFWPMac.scpt"

--process folder action

tell application "System Events"

launch

set folder actions enabled to true

set curScripts to (get attached scripts of folder printPath)

if curScripts is {} or item 1 of curScripts is not (actionScript as alias) then

try

attach action to folder printPath using actionScript

on error e

tell me to activate

display dialog "Error attaching folder action script:" & return & e

end try

else if curScripts is not {} and item 1 of curScripts is (actionScript as alias) then

tell folder action "Folder for PrintFiles"

set enabled to true

set enabled of script "PrintOrPDFWPMac.scpt" to true

end tell

end if

end tell

end setupPrintSys


on removePrintSystem()

-- if Unix folder has changed between home and documents, remove printing system

--  from other folder

tell application "Finder"

set ppExists to no

if exists folder (otherUnix & "Folder for PrintFiles") then

set ppExists to yes

try

set otherPrintPath to alias (otherUnix & "Folder for PrintFiles") as string

on error

tell me to activate

display dialog "Can't find old print path."

end try

end if

try

if exists folder (scriptPath & "Folder Action Scripts") then

set userScriptPath to alias (scriptPath & "Folder Action Scripts") as string

end if

end try

end tell

set actionScript to "PrintOrPDFWPMac.scpt"

tell application "System Events"

try

set curScripts to (attached scripts of otherPrintPath) as string

if curScripts contains actionScript then

if ppExists = yes then

try

tell folder action "Folder for PrintFiles"

set enabled to false

set enabled of script "PrintOrPDFWPMac.scpt" to false

end tell

end try

try

-- Detaches the Folder Action from the folder

remove action from otherPrintPath using action name actionScript

(*

try -- actCount not used in present version of script

set actCount to actCount + 1

end try

*)

end try

end if

end if

end try

end tell

tell application "Finder"

if exists file actionScript then

delete file actionScript

(*

try -- actCount not used in present version of script

set actCount to actCount + 1

end try

*)

end if

-- if PrintFiles folder is empty, then delete it !!!

if ppExists = yes then

set ppCount to count of (files in folder otherPrintPath)

if ppCount = 0 then

delete otherPrintPath

else

set dialogText to "The “Folder for PrintFiles” in your user folder contains files that you may want to save." & return & return & "The folder will now open. Move any files you wish to keep, then delete this folder."

tell me to activate

display dialog dialogText buttons {"OK"} default button 1 with icon caution

open otherPrintPath

(*

try -- actCount not used in present version of script

set actCount to actCount + 1

end try

*)

end if

end if

end tell

end removePrintSystem


-------------------------------------------------------------

-- subroutine for adding Spotlight and QuickLook filters


on addPlugins()

set userLibAlias to userLibPath as alias

set sysVers to ((system attribute "sysv") mod 4096 div 16)

set sysLibPath to path to library folder from local domain as text

set sysLibAlias to sysLibPath as alias

set spotFile to (path to me) & "Contents:Resources:Files:WordPerfect.mdimporter" as string

set spotFile to spotFile as alias

set quickFile to (path to me) & "Contents:Resources:Files:WordPerfect.qlgenerator" as string

set quickFile to quickFile as alias

set oldFileDate to date "Thursday, December 1, 2011 1 Dec 12:00:00 AM"

try

set sysSpotFolder to sysLibPath & "Spotlight" as alias

end try

set spotFound to true

try

set sysSpotFolder to sysLibPath & "Spotlight" as alias

on error

set spotFound to false

end try

set wpSpotFound to false

if spotFound is true then

set sysSpotPath to sysSpotFolder as text

set sysWPSpot to sysSpotPath & "WordPerfect.mdimporter"

tell application "Finder"

set wpSpotFound to false

if exists file sysWPSpot then

if (creation date of (info for file sysWPSpot)) comes after oldFileDate then

set wpSpotFound to true

end if

end if

end tell

end if

if wpSpotFound is false then

set userSpotFolderFound to true

try

set userSpotFolder to (userLibPath & "Spotlight") as alias

on error

set userSpotFolderFound to false

end try

if userSpotFolderFound is true then

set userSpotPath to userSpotFolder as text

set userWPSpot to userSpotPath & "WordPerfect.mdimporter"

tell application "Finder"

if exists file userWPSpot then

if (creation date of (info for file userWPSpot)) comes after oldFileDate then

set wpSpotFound to true

end if

end if

end tell

end if

end if

if wpSpotFound is false then

tell me to activate

display dialog "I will now install (or update) the WordPerfect Spotlight filter by Gero Hermann." & return & return & "The Finder may prompt you for your password." buttons {"OK"} with title msgTitle giving up after 5

-- try to copy file to system folder, if fails, to user folder

try

tell application "Finder"

set copy_file to duplicate spotFile to folder sysSpotFolder with replacing

end tell

on error

tell application "Finder"

try

make new folder at folder userLibAlias with properties {name:"Spotlight"}

end try

set userSpotFolder to userLibPath & "Spotlight" as alias

try

set copy_file to duplicate spotFile to folder userSpotFolder with replacing

end try

end tell

end try

end if

try

set sysQuickFolder to sysLibPath & "QuickLook" as alias

end try

set QuickFound to true

try

set sysQuickFolder to sysLibPath & "QuickLook" as alias

on error

set QuickFound to false

end try

set wpQuickFound to false

if QuickFound is true then

set sysQuickPath to sysQuickFolder as text

set sysWPQuick to sysQuickPath & "WordPerfect.qlgenerator"

tell application "Finder"

set wpQuickFound to false

if exists file sysWPQuick then

if (creation date of (info for file sysWPQuick)) comes after oldFileDate then

set wpQuickFound to true

end if

end if

end tell

end if

if wpQuickFound is false then

set userQuickFolderFound to true

try

set userQuickFolder to userLibPath & "QuickLook" as alias

on error

set userQuickFolderFound to false

end try

if userQuickFolderFound is true then

set userQuickPath to userQuickFolder as text

set userWPQuick to userQuickPath & "WordPerfect.qlgenerator"

tell application "Finder"

if exists file userWPQuick then

if (creation date of (info for file userWPQuick)) comes after oldFileDate then

set wpQuickFound to true

end if

end if

end tell

end if

end if

if wpQuickFound is false then

tell me to activate

display dialog "I will now install (or update) the WordPerfect QuickLook filter by Gero Hermann." & return & return & "The Finder may prompt you for your password." buttons {"OK"} with title msgTitle giving up after 5

try

tell application "Finder"

set copy_file to duplicate quickFile to folder sysQuickFolder with replacing

end tell

on error

tell application "Finder"

try

make new folder at folder userLibAlias with properties {name:"QuickLook"}

end try

set userQuickFolder to userLibPath & "QuickLook" as alias

try

set copy_file to duplicate quickFile to folder userQuickFolder with replacing

end try

end tell

end try

end if

end addPlugins


-------------------------------------------------------------

-- Other Subroutines


on getDspSizes()

set dspsizes to {}

set toolpath to ((path to me) as Unicode text) & "Contents:Resources:dspsizes"

set command to (quoted form of POSIX path of toolpath)

set output to paragraphs of (do shell script command)

repeat with dspinfo in output

set dspsizes to dspsizes & {({word 1, word 3} of dspinfo)}

end repeat

end getDspSizes


on simple_sort(my_list)

set the index_list to {}

set the sorted_list to {}

repeat (the number of items in my_list) times

set the low_item to ""

repeat with i from 1 to (number of items in my_list)

if i is not in the index_list then

set this_item to item i of my_list as text

if the low_item is "" then

set the low_item to this_item

set the low_item_index to i

else if this_item comes before the low_item then

set the low_item to this_item

set the low_item_index to i

end if

end if

end repeat

set the end of sorted_list to the low_item

set the end of the index_list to the low_item_index

end repeat

return the sorted_list

end simple_sort


on errorQuit(dialogText) -- Fatal error, quitting script

tell me to activate

display dialog dialogText buttons {"OK"} default button 1 with icon stop with title msgTitle giving up after 5

error number -128

end errorQuit


on cautionQuit(dialogText) -- Only a caution, possibly quit?

tell me to activate

display dialog dialogText buttons {"Continue?", "Quit"} default button 2 with icon caution with title msgTitle

set userChoice to button returned of result

if userChoice = "Quit" then

error number -128

end if

end cautionQuit


on bigName()

set runCount to runCount + 1

if runCount = 1 then set actionChoice to "copy"

set fullPathLength to (count characters of thePosPath)

set folderString to text 1 thru (fullPathLength - nameCount) of thePosPath

copy thePosPath to oldName

set newName to text 1 thru 31 of fileOnlyName

set changeToName to newName & "X" -- dummy variable to get into repeat loop

set addText to ""

set tries to 0

repeat

tell (count characters of changeToName) to if it > 0 and it < 32 then exit repeat

if tries > 0 and (count characters of changeToName) > 0 then

set addText to "Please enter a name with no more than 31 characters. The name you entered has " & (count characters of changeToName) & " characters." & return & return

else

set addText to ""

end if

set defBtn to 2

if actionChoice = "rename" then

set defBtn to 3

end if

tell me to activate

set fixName to display dialog "The file you selected cannot be opened in the WPMacApp because its name has more than 31 characters: " & return & return & "“" & fileOnlyName & "”" & return & return & "If you choose, I can copy this file to a new file with a shorter name, or I can rename the original file. I will then try to open the copied or renamed file in the WPMacApp." & return & return & "To copy or rename this file, accept or change the new name shown below. Do not enter more than 31 characters." & return & return & "Click “Skip this file” to continue without changing or opening this file." & return & return & "Click “Copy to new file” to create a copy of the file in the same folder as the original, with the new name that you enter below; the original file will not be changed." & return & return & "Click “Rename existing file” to rename the original file with the new name that you enter below." & return & return & addText & "Enter a new name below:" default answer newName buttons {"Skip this file", "Copy to new file", "Rename existing file"} default button defBtn with icon caution with title msgTitle

set changeToName to text returned of the result

set tries to tries + 1

if button returned of fixName = "Skip this file" then

set aliasForList to ""

return

end if

if button returned of fixName = "Copy to new file" then

set actionChoice to "copy"

end if

if button returned of fixName = "Rename existing file" then

set actionChoice to "rename"

end if

end repeat

set theQuestion to ""

if actionChoice = "copy" then

set theQuestion to "Proceed with copying your original file:" & return & return & "“" & fileOnlyName & "”" & return & return & "to a new file named:" & return & return & "“" & changeToName & "”"

end if

if actionChoice is "rename" then

set theQuestion to "Proceed with renaming your file:" & return & return & "“" & fileOnlyName & "”" & return & return & "with the new name:" & return & return & "“" & changeToName & "”"

end if

set icnPath to (path to "csrv")'s POSIX path & "CoreTypes.bundle/Contents/Resources/"

tell me to activate

set confirmChange to display dialog theQuestion buttons {"No, choose a different name", "Yes, continue"} default button 2 with icon questionIcon with title msgTitle

-- OR with icon POSIX file (icnPath & "MigrateAsst.icns") 

if button returned of confirmChange is "No, choose a different name" then

set changeToName to ""

bigName()

end if

if button returned of confirmChange is "Yes, continue" then

set outputFile to folderString & changeToName

set targetExists to true

try

do shell script "ls " & quoted form of outputFile

on error

set targetExists to false

end try

if targetExists is true then

tell me to activate

set overWrite to display dialog "Target file:" & return & return & "“" & changeToName & "”" & return & return & "already exists. Overwrite?" buttons {"No", "Yes"} default button 2 with icon caution with title msgTitle

if button returned of overWrite is "No" then

set changeToName to ""

set outputFile to ""

bigName()

end if

end if

if actionChoice = "rename" then

set shellVerb to "mv"

end if

if actionChoice = "copy" then

set shellVerb to "cp"

end if

do shell script shellVerb & space & quoted form of thePosPath & space & quoted form of outputFile

set aliasForList to POSIX file outputFile

end if

end bigName


-------------------------------------------------------------

-- subroutines for setting up local printers


on localPrinter()

try

do shell script "cupsctl 'BrowseLocalProtocols=\"cups dnssd lpd\"'"

end try

end localPrinter


on setupPrinter()

if doPrinterSetup is 1 then

set printerNames to (do shell script "lpstat  -l -p | grep -i Description: |awk -F'Description: ' '{print $2}' ") -- as list

set queueNames to (do shell script "lpstat -a | awk -F' accepting' '{print $1}'") -- as list

set printerList to (every paragraph of printerNames) as list

set queueList to (every paragraph of queueNames) as list

if printerList is "" then

tell me to activate

display dialog "No printers available to set up." & return & return & "When you have installed a printer and want to use it in WordPerfect, hold down the Option and Command keys when launching this application." buttons {"OK"} with title msgTitle giving up after 5

try

do shell script "echo " & theQueue & " > " & quoted form of (posixFolder & "/SetupDone")

end try

return

end if

if the (count of printerList) is 1 then

set thePrinter to {item 1 of printerList} as string

set theQueue to {item 1 of queueList} as string

-- if theQueue is "CUPS-PDF" then set choseCups to 1

tell me to activate

display dialog "I will now setup " & thePrinter & " for use in WordPerfect." buttons {"OK"} with title msgTitle giving up after 5

else

set thePrinter to (choose from list printerList with title "Printers" with prompt "Choose a printer to use with WordPerfect:")

-- removed from previous parenthesis: default items {item 1 of printerList} 

if thePrinter is false then

tell me to activate

display dialog "Printer setup cancelled. If you press OK or wait a few seconds, I will continue to launch the WPMacApp." buttons {"OK", "Cancel"} default button 1 with title msgTitle giving up after 5

if button returned of the result is "Cancel" then

error number -128

end if

set doPrinterSetup to 0

return

else

set thePrinter to item 1 of thePrinter

set item_num to my list_position(thePrinter, printerList)

set theQueue to item item_num in queueList

end if

end if

do shell script "echo " & theQueue & " > " & quoted form of (posixFolder & "/QueueName.unix")

do shell script "echo " & thePrinter & " >> " & quoted form of (posixFolder & "/QueueName.unix")

do shell script "cd " & quoted form of posixFolder & " ; tr '\\n' '\\r' < QueueName.unix > QueueName.txt"

do shell script "rm " & quoted form of (posixFolder & "/QueueName.unix")

tell application "System Events"

if UI elements enabled then

else

my setupUniversalAccess()

end if

end tell

tell application "System Preferences"

activate

reveal anchor "Main" of pane id "com.apple.preferences.sharing"

end tell

tell application "System Events"

tell process "System Preferences"

tell table 1 of scroll area 1 of group 1 of window 1

tell (1st row whose value of static text 1 is "Printer Sharing")

set selected to true

if value of checkbox 1 is 0 then

click checkbox 1

end if

end tell

end tell

delay 0.5

if Leopard is 1 then

set scrollArea to 2

else

set scrollArea to 3

end if

tell table 1 of scroll area scrollArea of group 1 of window 1

tell (1st row whose value of text field 1 is thePrinter)

set selected to true

if value of checkbox 1 is 0 then

click checkbox 1

end if

end tell

end tell

end tell

end tell

tell me to activate

display dialog "Please confirm that " & thePrinter & " is checked in the list of printers in the Printer Sharing menu, then click OK." & return & return & "Add a checkmark if it is not present."

tell application "System Preferences" to quit

end if

end setupPrinter


on list_position(this_item, this_list)

repeat with i from 1 to the count of this_list

if item i of this_list is this_item then return i

end repeat

return 0

end list_position


on setupCups()

if doCupsSetup is 1 then

-- test whether cups-pdf is installed

try

do shell script "ls -a /usr/libexec/cups/backend/cups-pdf"

on error

-- install cups-pdf if it's not already installed

tell me to activate

display dialog "Please follow the prompts to install CUPS-PDF. Accept the default settings." buttons {"OK", "Cancel"} default button 1 with title msgTitle giving up after 20

if button returned of the result is "Cancel" then

tell me to activate

display dialog "Script cancelled." buttons {"OK"} with title msgTitle giving up after 10 with icon stop

error number -128

end if

tell application "System Events"

set procList to (name of every process)

end tell

if procList contains "Installer" then

tell me to activate

display dialog "Please quit any installation program that may be running and try again." buttons {"OK"} giving up after 10

error number -128

end if

tell application "Finder" to open cupsPkg

set cupsRunning to true

repeat until cupsRunning is false

tell application "System Events"

set procList to (name of every process)

end tell

if procList contains "Installer" then

else

set cupsRunning to false

end if

delay 1

end repeat

end try

try

do shell script "lpadmin -p CUPS-PDF -v cups-pdf:/ -m PostscriptColor.ppd -E -o printer-is-shared=true"

on error

tell me to activate

display dialog "Error creating CUPS-PDF printer. Exiting." buttons {"OK"} giving up after 10

error number -128

end try

tell application "Printer Setup Utility"

set nameList to the name of every printer

set cupsOK to 0

if nameList contains "CUPS-PDF" then set cupsOK to 1

end tell

if cupsOK is 0 then

tell me to activate

display dialog "CUPS-PDF installation seems not to have completed. Please restart this application and start again." buttons {"OK"} with title msgTitle giving up after 5

error number -128

end if

set thePrinter to "CUPS-PDF" as string

set theQueue to "CUPS-PDF" as string

do shell script "echo " & theQueue & " > " & quoted form of (posixFolder & "/QueueName.unix")

do shell script "echo " & thePrinter & " >> " & quoted form of (posixFolder & "/QueueName.unix")

do shell script "cd " & quoted form of posixFolder & " ; tr '\\n' '\\r' < QueueName.unix > QueueName.txt"

do shell script "rm " & quoted form of (posixFolder & "/QueueName.unix")

tell application "System Preferences"

activate

reveal anchor "Main" of pane id "com.apple.preferences.sharing"

end tell

tell application "System Events"

tell process "System Preferences"

tell table 1 of scroll area 1 of group 1 of window 1

tell (1st row whose value of static text 1 is "Printer Sharing")

set selected to true

if value of checkbox 1 is 0 then

click checkbox 1

end if

end tell

end tell

delay 0.5

if Leopard is 1 then

set scrollArea to 2

else

set scrollArea to 3

end if

tell table 1 of scroll area scrollArea of group 1 of window 1

tell (1st row whose value of text field 1 is "CUPS-PDF")

set selected to true

if value of checkbox 1 is 0 then

click checkbox 1

end if

end tell

end tell

end tell

end tell

tell me to activate

display dialog "Please confirm that " & thePrinter & " is checked in the list of printers in the Printer Sharing menu, then click OK." & return & return & "Add a checkmark if it is not present."

tell application "System Preferences" to quit

end if

end setupCups


on makeCupsShortcut()

-- display dialog "If you do not already have an alias to the output directory for PDF files created by the CUPS-PDF driver in the WPMacApp, I will create one for you." & return & return & "Please wait while I search for an existing alias." buttons {"OK"} with title msgTitle giving up after 7

set searchLoc to "-onlyin ~/ "

set prefixCmd to "mdfind "

-- 'Alias' is in (escaped) double quotes

-- the command is in single quotes

-- the string is in double quotes

set suffixCmd to "'kMDItemKind == \"Alias\"'"

-- use Spotlight to find aliases

set myCommand to prefixCmd & searchLoc & suffixCmd

set theList to paragraphs of (do shell script myCommand)

set foundAlias to 0

tell application "Finder"

repeat with p in theList

set thisAlias to p as POSIX file as alias -- coerce Unicode text to POSIX file path to AppleScript alias

try

if original item of thisAlias is folder "ANONYMOUS" of folder "cups-pdf" of folder "spool" of folder "var" of item "private" of startup disk then

set foundAlias to 1

set aliasPath to p as string

exit repeat

end if

end try

end repeat

end tell

if foundAlias is 1 then

else

tell application "Finder"

try

set pdfFolder to (POSIX file "/private/var/spool/cups-pdf/ANONYMOUS") as alias

on error

tell me to activate

display dialog "PDF output folder not found. Please reinstall CUPS-PDF."

end try

set madeAlias to 0

try

make new alias file at (path to the desktop folder from user domain) to pdfFolder with properties {name:"WPMac-PDF"}

set madeAlias to 1

on error

tell me to activate

display dialog "Could not create an alias to the PDF output folder"

end try

end tell

if madeAlias is 1 then

tell me to activate

display dialog "I created an alias on your desktop named WPMac-PDF. This is an alias to the folder that contains the output of the CUPS-PDF printer in the WPMacApp. You may move this alias anywhere you choose." & return & return & "If you choose to delete the alias, you may find the PDF output at" & return & return & "/Users/Shared/CUPS-PDF/ANONYMOUS" buttons {"OK"} with title msgTitle

end if

end if

end makeCupsShortcut


on printerPrompt()

if suppressPrinterPrompt is 0 then

set doCupsSetup to 0

set ptrButton to ""

tell me to activate

display dialog "Setup an OS X printer or a PDF creator for use in the WPMacApp?" & return & return & "(To install the PDF creator or a printer at a later time, hold down the Command and Option keys when starting the application.)" buttons {"Setup printer", "Setup PDF creator", "Not now"} default button 1 with title msgTitle

set ptrButton to button returned of the result

if ptrButton is "Not now" then

set fileNotNow to 0

if setupDoneOnce is 0 then

try

do shell script "ls -a " & quoted form of (posixFolder & "/NotNow")

set fileNotNow to 1

on error

try

do shell script "echo ContentOfNotNowFile > " & quoted form of (posixFolder & "/NotNow")

end try

-- display dialog "Just wrote Notnow to " & quoted form of (posixFolder & "/NotNow")

set fileNotNow to 0

end try

end if

if fileNotNow is 1 then

tell me to activate

display dialog "Do you want me to continue to ask if you want to setup a printer or PDF creator for WordPerfect, or do you want me to stop asking?" & return & return & "If you want me to stop asking, you can setup a printer at any time by holding down Command and Option when starting the application." buttons {"Continue asking", "Stop asking"} default button 1 with title msgTitle

if button returned of result is "Stop asking" then

try

do shell script "echo ContentOfNeverAskFile > " & quoted form of (posixFolder & "/NeverAsk")

end try

try

do shell script "rm " & quoted form of (posixFolder & "/NotNow")

end try

else

try

do shell script "rm " & quoted form of (posixFolder & "/SetupDone")

end try

end if

end if

set doPrinterSetup to 0

set doCupsSetup to 0

else

if ptrButton is "Setup printer" then

set doPrinterSetup to 1

set doCupsSetup to 0

else

if ptrButton is "Setup PDF creator" then

set doPrinterSetup to 0

set doCupsSetup to 1

end if

end if

end if

-- end if

end if

end printerPrompt


on setupUniversalAccess()

tell application "System Events"

if UI elements enabled then

else

-- GUI scripting not enabled; display an alert

tell me to activate

display dialog "To set up your printer for WordPerfect I must turn on the OS X feature “Enable access for assistive devices”." & return & return & "May I turn on this feature?" & return & return & "If you answer Yes, OS X will prompt you for a password." buttons {"No", "Yes"} default button 2 with icon caution with title msgTitle

set enableGUI to button returned of result

if enableGUI is "No" then

tell me to activate

display dialog "You may enable the required feature in System Preferences, in the Universal Access pane, by adding a checkbox next to  “Enable access for assistive devices”." & return & return & "This application will now close." buttons {"OK"} default button 1 with icon caution with title msgTitle

quit

error number -128

else

tell application "System Events" to set UI elements enabled to true

end if

end if

end tell

delay 1

end setupUniversalAccess


on getMyName()

-- in case we need to use selected unix folder

set vmPath to (path to me) & "Contents:Resources:Files:MacOS.sheepvm" as string

set vmFile to vmPath as alias

set vmPosix to (POSIX path of vmFile) as string

-- set extfsPosix to (vmPosix & "extfsposix")

set extfsPath to (vmPosix & "extfspath")

tell application "System Events" to set myName to name of (get properties of (path to me))

set myName to text 1 thru -5 of myName

if myName contains "setup" then

set extraString to return & return & "Remove “Setup” from my name to hide this menu next time"

my askforUnix(extraString)

end if

end getMyName


on askforUnix(extraString)

tell me to activate

display dialog "Select an OS X folder to use as the “Unix” folder in SheepShaver." & extraString buttons {"Documents folder", "Home folder", "Choose another…"} default button 1 with title msgTitle

if button returned of result is "Documents folder" then

set useHomeFolder to 0

try

-- do shell script "rm " & quoted form of extfsPosix

do shell script "rm " & quoted form of extfsPath

end try

else if button returned of result is "Home folder" then

set useHomeFolder to 1

try

-- do shell script "rm " & quoted form of extfsPosix

do shell script "rm " & quoted form of extfsPath

end try

else if button returned of result is "Choose another…" then

set myUnix to choose folder with prompt "Select a folder for the “Unix” folder in SheepShaver and click Choose:"

-- set unixPosixPath to POSIX path of myUnix

set unixPath to myUnix as text

-- do shell script "echo " & quoted form of unixPosixPath & " > " & quoted form of extfsPosix

do shell script "echo " & unixPath & " > " & quoted form of extfsPath

end if

end askforUnix