1 | (* by F. Farges; farges@univ-mlv.fr ; changes by B. Toby brian.toby@nist.gov |
---|
2 | based on various AppleScripts for X11 |
---|
3 | |
---|
4 | It can launch expgui by double clicking or by dropping a data file or folder over that app. |
---|
5 | *) |
---|
6 | |
---|
7 | |
---|
8 | (* |
---|
9 | -------------------------------------------- |
---|
10 | Define subroutines used in later sections of code |
---|
11 | -------------------------------------------- |
---|
12 | *) |
---|
13 | |
---|
14 | (* get directory from a file name *) |
---|
15 | on GetParentPath(theFile) |
---|
16 | tell application "Finder" to return container of theFile as text |
---|
17 | end GetParentPath |
---|
18 | |
---|
19 | (* find a wish executable or return an error *) |
---|
20 | on GetWishExe(myPath) |
---|
21 | set WishExe to myPath & "ncnrpack-osx" |
---|
22 | set WishExe to the POSIX path of WishExe |
---|
23 | tell application "System Events" |
---|
24 | if (file WishExe exists) then |
---|
25 | return WishExe |
---|
26 | end if |
---|
27 | set WishExe to "/sw/bin/wish" |
---|
28 | if (file WishExe exists) then |
---|
29 | return WishExe |
---|
30 | end if |
---|
31 | error ("Error: Tcl/Tk executable was not found. See installation instructions.") |
---|
32 | end tell |
---|
33 | end GetWishExe |
---|
34 | |
---|
35 | (* test if a file is present and exit with an error message if it is not *) |
---|
36 | on TestFilePresent(appwithpath) |
---|
37 | tell application "System Events" |
---|
38 | if (file appwithpath exists) then |
---|
39 | else |
---|
40 | error ("Error: file " & appwithpath & " not found. This EXPGUI AppleScript must be run from the gsas directory. Did you move it?") |
---|
41 | end if |
---|
42 | end tell |
---|
43 | end TestFilePresent |
---|
44 | |
---|
45 | (* |
---|
46 | -------------------------------------------------------------- |
---|
47 | this section responds to a double-click. It starts X11 and then expgui, provided |
---|
48 | the expgui script is in the expgui folder of the location of this applescript |
---|
49 | o it finds the location of the current script and finds the expgui |
---|
50 | tcl script relative to the applescript |
---|
51 | o it finds a version of Tcl/Tk to run either relative to the script location |
---|
52 | or if not present there, in the place where Fink would install it |
---|
53 | o it opens X11 (if needed) |
---|
54 | o it makes X11 active (brings to the front) |
---|
55 | o then it converts the colon-delimited macintosh file location to a POSIX filename |
---|
56 | o for every non-directory file dragged into the icon, it tries to open that file in soffice |
---|
57 | -------------------------------------------------------------- |
---|
58 | *) |
---|
59 | on run |
---|
60 | set myPath to (path to me) |
---|
61 | set ParentPath to GetParentPath(myPath) |
---|
62 | set appwithpath to ParentPath & "expgui:expgui" |
---|
63 | TestFilePresent(appwithpath) |
---|
64 | set posixapp to quoted form of the POSIX path of appwithpath |
---|
65 | set WishExe to the quoted form of GetWishExe(ParentPath) |
---|
66 | |
---|
67 | tell application "Finder" |
---|
68 | launch application "X11" |
---|
69 | end tell |
---|
70 | |
---|
71 | tell application "X11" |
---|
72 | activate |
---|
73 | end tell |
---|
74 | |
---|
75 | set results to do shell script "cd ~;DISPLAY=:0.0 PATH=$PATH:/usr/local/bin:/usr/X11R6/bin " & WishExe & " " & posixapp & " > /dev/null 2>&1 &" |
---|
76 | end run |
---|
77 | |
---|
78 | (* |
---|
79 | ---------------------------------------------------------------------- |
---|
80 | this section handles opening files dragged into the AppleScript |
---|
81 | o it finds the location of the current script and finds the expgui |
---|
82 | tcl script relative to the applescript |
---|
83 | o it finds a version of Tcl/Tk to run either relative to the script location |
---|
84 | or if not present there, in the place where Fink would install it |
---|
85 | o it opens X11 (if needed) |
---|
86 | o it goes through the list of files dragged in |
---|
87 | o then it converts the colon-delimited macintosh file location to a POSIX filename |
---|
88 | o for every non-directory file dragged into the icon, it tries to open that file in soffice |
---|
89 | ----------------------------------------------------------------------- |
---|
90 | *) |
---|
91 | |
---|
92 | on open names |
---|
93 | |
---|
94 | set myPath to (path to me) |
---|
95 | set ParentPath to GetParentPath(myPath) |
---|
96 | set appwithpath to GetParentPath(myPath) & "expgui:expgui" |
---|
97 | TestFilePresent(appwithpath) |
---|
98 | set posixapp to the quoted form of the POSIX path of appwithpath |
---|
99 | set WishExe to the quoted form of GetWishExe(ParentPath) |
---|
100 | |
---|
101 | tell application "Finder" |
---|
102 | launch application "X11" |
---|
103 | end tell |
---|
104 | |
---|
105 | set filePath to "" |
---|
106 | repeat with i in names |
---|
107 | set macpath to (i as string) |
---|
108 | if macpath ends with ":" then |
---|
109 | (* if this is a directory; start EXPGUI in that folder *) |
---|
110 | set filename to the quoted form of the POSIX path of macpath |
---|
111 | 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 &" |
---|
112 | else if macpath ends with ".EXP" then |
---|
113 | (* if this is an experiment file, open it *) |
---|
114 | set filename to the quoted form of the POSIX path of macpath |
---|
115 | set results to do shell script "cd ~;DISPLAY=:0.0 PATH=$PATH:/usr/local/bin:/usr/X11R6 " & WishExe & " " & posixapp & " " & filename & " > /dev/null 2>&1 &" |
---|
116 | else |
---|
117 | display dialog "This is not a valid GSAS Experiment file: " & macpath with icon caution buttons {"OK"} |
---|
118 | end if |
---|
119 | end repeat |
---|
120 | end open |
---|