GRASS.applescript 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. -- Created by William Kyngesburye on 2006-12-12.
  2. -- GRASS Applescript startup
  3. -- COPYRIGHT: (C) 2006-2008 by the GRASS Development Team
  4. -- This program is free software under the GPL (>=v2)
  5. -- Read the file COPYING that comes with GRASS for details.
  6. -- note: handler order on launch:
  7. -- 1-will finish launching (good place to check prefs; no nibs loaded yet)
  8. -- 2-launched (good place to show initial windows or dialogs)
  9. -- 2.5-open?
  10. -- 3-idle (waits for user action)
  11. --
  12. -- idle is supposed to be last, but open seems to cause it to think
  13. -- it's not idle, so we can process drag-n-drop before idling. No docs
  14. -- say explicitly that this is the case, so speed of Mac and process load
  15. -- could affect this.
  16. property grassMap : ""
  17. property grassGui : ""
  18. property grassLaunched : false
  19. on will finish launching theObject
  20. set grassLaunched to false
  21. -- eventually, catch modifier key here? to show gui choice
  22. end will finish launching
  23. --on launch theObject
  24. --end launch
  25. on open maps
  26. --display dialog (count of maps)
  27. if count of maps is 1 then
  28. if (folder of (info for (item 1 of maps))) then
  29. set grassMap to " " & (quoted form of (POSIX path of (item 1 of maps)))
  30. end if
  31. end if
  32. launchgrass()
  33. end open
  34. on idle theObject
  35. if not grassLaunched then
  36. launchgrass()
  37. end if
  38. end launched
  39. on launchgrass()
  40. set grassLaunched to true
  41. set grass_path to (posix path of (path to me as string)) & "Contents/MacOS/"
  42. set grass_startup to (quoted form of (grass_path & "grass.sh"))
  43. set grassRun to grass_startup & grassGui & grassMap & "; exit"
  44. set TerminalRunning to false
  45. try
  46. if ((do shell script "ps -axc | grep '\\bTerminal\\b'") is not null) then
  47. set TerminalRunning to true
  48. end if
  49. end try
  50. tell application "Terminal"
  51. activate
  52. if TerminalRunning then
  53. do script (grassRun)
  54. else
  55. do script (grassRun) in window 1
  56. end if
  57. end tell
  58. tell me to quit
  59. end launchgrass