Advertisement
devinteske

imunes.applescript

Apr 28th, 2022
4,070
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env osascript
  2. # -*- tab-width: 4 -*- ;; Emacs
  3. # vi: set ts=4 sw=4 noet ft=applescript :: Vi/ViM
  4. #-
  5. ############################################################ IDENT(1)
  6. #
  7. # $Title: AppleScript to launch imunes remotely via X11Forward $
  8. # $Copyright: 2019-2022 Devin Teske. All rights reserved. $
  9. # $FrauBSD$
  10. #
  11. ############################################################ CONFIGURATION
  12.  
  13. #
  14. # qmon host
  15. #
  16. property imunesHost : "hostname"
  17.  
  18. ############################################################ FUNCTIONS
  19.  
  20. on replaceString(theText, oldString, newString)
  21.     local ASTID, theText, oldString, newString, lst
  22.     set ASTID to AppleScript's text item delimiters
  23.     try
  24.         considering case
  25.             set AppleScript's text item delimiters to oldString
  26.             set lst to every text item of theText
  27.             set AppleScript's text item delimiters to newString
  28.             set theText to lst as string
  29.         end considering
  30.         set AppleScript's text item delimiters to ASTID
  31.         return theText
  32.     on error eMsg number eNum
  33.         set AppleScript's text item delimiters to ASTID
  34.         error "Can't replaceString: " & eMsg number eNum
  35.     end try
  36. end replaceString
  37.  
  38. on shellCmd(shellText)
  39.     # Replace tabs in shellText with spaces
  40.     replaceString(shellText, "  ", " ")
  41.     # Join lines
  42.     replaceString(result, linefeed, "")
  43.     tell application "Terminal" to do script result
  44. end shellCmd
  45.  
  46. ############################################################ MAIN
  47.  
  48. on run
  49.     tell application "XQuartz" to run
  50.     #
  51.     # Perform X11 forwarding with ssh(8) to the qmon server and then run qmon
  52.     #
  53.     shellCmd("
  54.         xhost + || : errors ignored
  55.         ssh -Yf " & imunesHost & " '
  56.             imunes;
  57.             exit;
  58.         ';
  59.         exit;
  60.     ")
  61. end run
  62.  
  63. ################################################################################
  64. # END
  65. ################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement