Changes between Version 1 and Version 2 of AppleScript


Ignore:
Timestamp:
Apr 19, 2011 10:26:40 AM (10 years ago)
Author:
toby
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AppleScript

    v1 v2  
    22
    33Versions of an !AppleScript for starting EXPGUI are provided below, different versions appear to be needed for [#leopard leopard/10.5], [#leopard snowleopard/10.6] and [#tiger tiger/10.4]. This script must be placed in the EXPGUI folder (so that it can find the files). You can drag this EXPGUI app to the dock or make an alias which can be moved, but don't move the script unless you plan to hard-code the file locations. Clicking on the app starts EXPGUI and dragging .EXP files onto the app opens the program with those files. Dropping a folder onto the EXPGUI app will cause EXPGUI to be started within that folder. It is possible to drag both a directory and files onto the EXPGUI app.
     4
     5I find that sometimes it works better to recompile the !AppleScript in the !AppleScript Editor (Applications/Utilities or in 10.4 Applications/AppleScript/AppleScript Utility)
    46
    57== This version of the script has been tested in 10.5 and 10.6. == #leopard
    68{{{
     9(*   Launch EXPGUI: launches EXPGUI by double clicking on app or by dropping a data file or folder on the app
     10
     11version for 10.6 (& 10.5?)
     12
     13original script by F. Farges; farges@univ-mlv.fr ;  changes by B. Toby brian.toby@anl.gov
     14
     15To debug this script, I suggest changing the lines with
     16        set results to do shell script ...
     17to send output to path /tmp/expgui.txt rather than /dev/null (use of >> rather than > is a good idea too.)
     18*)
     19
     20
     21(*--------------------------------------------------------
     22Define subroutines  used in later sections of code
     23-----------------------------------------------------------
     24*)
     25
     26(*  get  directory  from a file name *)
     27on GetParentPath(theFile)
     28        tell application "Finder" to return container of theFile as text
     29end GetParentPath
     30
     31(* find a wish executable or return an error *)
     32on 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
     45end GetWishExe
     46
     47(* test if a file is present and exit with an error message if it is not  *)
     48on 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
     55end TestFilePresent
     56
     57(*
     58--------------------------------------------------------------
     59this section responds to a double-click. It starts X11 and then expgui, provided
     60the 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*)
     70on 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 &"
     83end run
     84
     85(*
     86----------------------------------------------------------------------
     87this 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
     99on 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
     127end open
    7128}}}
    8129
    9130== This version runs in 10.4 (Tiger) and 10.3 as well, I am pretty sure. == #tiger
    10131{{{
     132(*   Launch EXPGUI: launches EXPGUI by double clicking on app or by dropping a data file or folder on the app
     133
     134version for 10.4
     135
     136original script by F. Farges; farges@univ-mlv.fr ;  changes by B. Toby brian.toby@anl.gov
     137
     138corrected 4/14/2010 BHT
     139
     140*)
     141
     142
     143(*
     144--------------------------------------------
     145Define subroutines  used in later sections of code
     146--------------------------------------------
     147*)
     148
     149(*  get  directory  from a file name *)
     150on GetParentPath(theFile)
     151        tell application "Finder" to return container of theFile as text
     152end GetParentPath
     153
     154(* find a wish executable or return an error *)
     155on 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
     168end GetWishExe
     169
     170(* test if a file is present and exit with an error message if it is not  *)
     171on 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
     178end TestFilePresent
     179
     180(*
     181--------------------------------------------------------------
     182this section responds to a double-click. It starts X11 and then expgui, provided
     183the 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*)
     194on 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 &"
     211end run
     212
     213(*
     214----------------------------------------------------------------------
     215this 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
     227on 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
     255end open
    11256}}}