| 9 | (* Launch EXPGUI: launches EXPGUI by double clicking on app or by dropping a data file or folder on the app |
| 10 | |
| 11 | version for 10.6 (& 10.5?) |
| 12 | |
| 13 | original script by F. Farges; farges@univ-mlv.fr ; changes by B. Toby brian.toby@anl.gov |
| 14 | |
| 15 | To debug this script, I suggest changing the lines with |
| 16 | set results to do shell script ... |
| 17 | to send output to path /tmp/expgui.txt rather than /dev/null (use of >> rather than > is a good idea too.) |
| 18 | *) |
| 19 | |
| 20 | |
| 21 | (*-------------------------------------------------------- |
| 22 | Define subroutines used in later sections of code |
| 23 | ----------------------------------------------------------- |
| 24 | *) |
| 25 | |
| 26 | (* get directory from a file name *) |
| 27 | on GetParentPath(theFile) |
| 28 | tell application "Finder" to return container of theFile as text |
| 29 | end GetParentPath |
| 30 | |
| 31 | (* find a wish executable or return an error *) |
| 32 | on GetWishExe(myPath) |
| 33 | set WishExe to myPath & "exe:ncnrpack" |
| 34 | set WishExe to the POSIX path of WishExe |
| 35 | tell application "System Events" |
| 36 | if (file WishExe exists) then |
| 37 | return WishExe |
| 38 | end if |
| 39 | (*set WishExe to "/sw/bin/wish" |
| 40 | if (file WishExe exists) then |
| 41 | return WishExe |
| 42 | end if*) |
| 43 | error ("Error: Tcl/Tk executable, " & WishExe & " was not found. See installation instructions.") |
| 44 | end tell |
| 45 | end GetWishExe |
| 46 | |
| 47 | (* test if a file is present and exit with an error message if it is not *) |
| 48 | on TestFilePresent(appwithpath) |
| 49 | tell application "System Events" |
| 50 | if (file appwithpath exists) then |
| 51 | else |
| 52 | error ("Error: file " & appwithpath & " not found. This EXPGUI AppleScript must be run from the gsas directory. Did you move it?") |
| 53 | end if |
| 54 | end tell |
| 55 | end TestFilePresent |
| 56 | |
| 57 | (* |
| 58 | -------------------------------------------------------------- |
| 59 | this section responds to a double-click. It starts X11 and then expgui, provided |
| 60 | the expgui script is in the expgui folder of the location of this applescript |
| 61 | o it finds the location of the current script and finds the expgui |
| 62 | tcl script relative to the applescript |
| 63 | o it finds a version of Tcl/Tk to run either relative to the script location |
| 64 | or if not present there, in the place where Fink would install it |
| 65 | o it opens X11 (if needed) |
| 66 | o then it converts the colon-delimited macintosh file location to a POSIX filename |
| 67 | o for every non-directory file dragged into the icon, it tries to open that file in soffice |
| 68 | -------------------------------------------------------------- |
| 69 | *) |
| 70 | on run |
| 71 | set myPath to (path to me) |
| 72 | set ParentPath to GetParentPath(myPath) |
| 73 | set appwithpath to ParentPath & "expgui:expgui" |
| 74 | TestFilePresent(appwithpath) |
| 75 | set posixapp to quoted form of the POSIX path of appwithpath |
| 76 | set WishExe to the quoted form of GetWishExe(ParentPath) |
| 77 | |
| 78 | tell application "Finder" |
| 79 | launch application "X11" |
| 80 | end tell |
| 81 | |
| 82 | set results to do shell script "cd ~;DISPLAY=:0.0 PATH=$PATH:/usr/local/bin:/usr/X11R6/bin " & WishExe & " " & posixapp & " > /dev/null 2>&1 &" |
| 83 | end run |
| 84 | |
| 85 | (* |
| 86 | ---------------------------------------------------------------------- |
| 87 | this section handles opening files dragged into the AppleScript |
| 88 | o it finds the location of the current script and finds the expgui |
| 89 | tcl script relative to the applescript |
| 90 | o it finds a version of Tcl/Tk to run either relative to the script location |
| 91 | or if not present there, in the place where Fink would install it |
| 92 | o it opens X11 (if needed) |
| 93 | o it goes through the list of files dragged in |
| 94 | o then it converts the colon-delimited macintosh file location to a POSIX filename |
| 95 | o for every non-directory file dragged into the icon, it tries to open that file in soffice |
| 96 | ----------------------------------------------------------------------- |
| 97 | *) |
| 98 | |
| 99 | on open names |
| 100 | |
| 101 | set myPath to (path to me) |
| 102 | set ParentPath to GetParentPath(myPath) |
| 103 | set appwithpath to GetParentPath(myPath) & "expgui:expgui" |
| 104 | TestFilePresent(appwithpath) |
| 105 | set posixapp to the quoted form of the POSIX path of appwithpath |
| 106 | set WishExe to the quoted form of GetWishExe(ParentPath) |
| 107 | |
| 108 | tell application "Finder" |
| 109 | launch application "X11" |
| 110 | end tell |
| 111 | |
| 112 | set filePath to "" |
| 113 | repeat with i in names |
| 114 | set macpath to (i as string) |
| 115 | if macpath ends with ":" then |
| 116 | (* if this is a directory; start EXPGUI in that folder *) |
| 117 | set filename to the quoted form of the POSIX path of macpath |
| 118 | set results to do shell script "cd " & filename & ";DISPLAY=:0.0 PATH=$PATH:/usr/local/bin:/usr/X11R6/bin " & WishExe & " " & posixapp & " > /dev/null 2>&1 &" |
| 119 | else if macpath ends with ".EXP" then |
| 120 | (* if this is an experiment file, open it *) |
| 121 | set filename to the quoted form of the POSIX path of macpath |
| 122 | set results to do shell script "cd ~;DISPLAY=:0.0 PATH=$PATH:/usr/local/bin:/usr/X11R6/bin " & WishExe & " " & posixapp & " " & filename & " > /dev/null 2>&1 &" |
| 123 | else |
| 124 | display dialog "This is not a valid GSAS Experiment file: " & macpath with icon caution buttons {"OK"} |
| 125 | end if |
| 126 | end repeat |
| 127 | end open |
| 132 | (* Launch EXPGUI: launches EXPGUI by double clicking on app or by dropping a data file or folder on the app |
| 133 | |
| 134 | version for 10.4 |
| 135 | |
| 136 | original script by F. Farges; farges@univ-mlv.fr ; changes by B. Toby brian.toby@anl.gov |
| 137 | |
| 138 | corrected 4/14/2010 BHT |
| 139 | |
| 140 | *) |
| 141 | |
| 142 | |
| 143 | (* |
| 144 | -------------------------------------------- |
| 145 | Define subroutines used in later sections of code |
| 146 | -------------------------------------------- |
| 147 | *) |
| 148 | |
| 149 | (* get directory from a file name *) |
| 150 | on GetParentPath(theFile) |
| 151 | tell application "Finder" to return container of theFile as text |
| 152 | end GetParentPath |
| 153 | |
| 154 | (* find a wish executable or return an error *) |
| 155 | on GetWishExe(myPath) |
| 156 | set WishExe to myPath & "exe:ncnrpack" |
| 157 | set WishExe to the POSIX path of WishExe |
| 158 | tell application "System Events" |
| 159 | if (file WishExe exists) then |
| 160 | return WishExe |
| 161 | end if |
| 162 | (*set WishExe to "/sw/bin/wish" |
| 163 | if (file WishExe exists) then |
| 164 | return WishExe |
| 165 | end if*) |
| 166 | error ("Error: Tcl/Tk executable, " & WishExe & " was not found. See installation instructions.") |
| 167 | end tell |
| 168 | end GetWishExe |
| 169 | |
| 170 | (* test if a file is present and exit with an error message if it is not *) |
| 171 | on TestFilePresent(appwithpath) |
| 172 | tell application "System Events" |
| 173 | if (file appwithpath exists) then |
| 174 | else |
| 175 | error ("Error: file " & appwithpath & " not found. This EXPGUI AppleScript must be run from the gsas directory. Did you move it?") |
| 176 | end if |
| 177 | end tell |
| 178 | end TestFilePresent |
| 179 | |
| 180 | (* |
| 181 | -------------------------------------------------------------- |
| 182 | this section responds to a double-click. It starts X11 and then expgui, provided |
| 183 | the expgui script is in the expgui folder of the location of this applescript |
| 184 | o it finds the location of the current script and finds the expgui |
| 185 | tcl script relative to the applescript |
| 186 | o it finds a version of Tcl/Tk to run either relative to the script location |
| 187 | or if not present there, in the place where Fink would install it |
| 188 | o it opens X11 (if needed) |
| 189 | o it makes X11 active (brings to the front) |
| 190 | o then it converts the colon-delimited macintosh file location to a POSIX filename |
| 191 | o for every non-directory file dragged into the icon, it tries to open that file in soffice |
| 192 | -------------------------------------------------------------- |
| 193 | *) |
| 194 | on run |
| 195 | set myPath to (path to me) |
| 196 | set ParentPath to GetParentPath(myPath) |
| 197 | set appwithpath to ParentPath & "expgui:expgui" |
| 198 | TestFilePresent(appwithpath) |
| 199 | set posixapp to quoted form of the POSIX path of appwithpath |
| 200 | set WishExe to the quoted form of GetWishExe(ParentPath) |
| 201 | |
| 202 | tell application "Finder" |
| 203 | launch application "X11" |
| 204 | end tell |
| 205 | |
| 206 | tell application "X11" (* needed in <=10.4, I think *) |
| 207 | activate |
| 208 | end tell |
| 209 | |
| 210 | set results to do shell script "cd ~;DISPLAY=:0.0 PATH=$PATH:/usr/local/bin:/usr/X11R6/bin " & WishExe & " " & posixapp & " > /dev/null 2>&1 &" |
| 211 | end run |
| 212 | |
| 213 | (* |
| 214 | ---------------------------------------------------------------------- |
| 215 | this section handles opening files dragged into the AppleScript |
| 216 | o it finds the location of the current script and finds the expgui |
| 217 | tcl script relative to the applescript |
| 218 | o it finds a version of Tcl/Tk to run either relative to the script location |
| 219 | or if not present there, in the place where Fink would install it |
| 220 | o it opens X11 (if needed) |
| 221 | o it goes through the list of files dragged in |
| 222 | o then it converts the colon-delimited macintosh file location to a POSIX filename |
| 223 | o for every non-directory file dragged into the icon, it tries to open that file in soffice |
| 224 | ----------------------------------------------------------------------- |
| 225 | *) |
| 226 | |
| 227 | on open names |
| 228 | |
| 229 | set myPath to (path to me) |
| 230 | set ParentPath to GetParentPath(myPath) |
| 231 | set appwithpath to GetParentPath(myPath) & "expgui:expgui" |
| 232 | TestFilePresent(appwithpath) |
| 233 | set posixapp to the quoted form of the POSIX path of appwithpath |
| 234 | set WishExe to the quoted form of GetWishExe(ParentPath) |
| 235 | |
| 236 | tell application "Finder" |
| 237 | launch application "X11" |
| 238 | end tell |
| 239 | |
| 240 | set filePath to "" |
| 241 | repeat with i in names |
| 242 | set macpath to (i as string) |
| 243 | if macpath ends with ":" then |
| 244 | (* if this is a directory; start EXPGUI in that folder *) |
| 245 | set filename to the quoted form of the POSIX path of macpath |
| 246 | set results to do shell script "cd " & filename & ";DISPLAY=:0.0 PATH=$PATH:/usr/local/bin:/usr/X11R6/bin " & WishExe & " " & posixapp & " > /dev/null 2>&1 &" |
| 247 | else if macpath ends with ".EXP" then |
| 248 | (* if this is an experiment file, open it *) |
| 249 | set filename to the quoted form of the POSIX path of macpath |
| 250 | set results to do shell script "cd ~;DISPLAY=:0.0 PATH=$PATH:/usr/local/bin:/usr/X11R6/bin " & WishExe & " " & posixapp & " " & filename & " > /dev/null 2>&1 &" |
| 251 | else |
| 252 | display dialog "This is not a valid GSAS Experiment file: " & macpath with icon caution buttons {"OK"} |
| 253 | end if |
| 254 | end repeat |
| 255 | end open |