Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for kixmacro.kix

(view source code of kixmacro.kix as plain text)

  1. ; KixMacro.kix,  Version 2.00 for Windows
  2. ; Creates a temporary batch file to store Kix
  3. ; macro results in an environment variable
  4. ;
  5. ; Written by Rob van der Woude
  6. ; http://www.robvanderwoude.com
  7. ;
  8. ; NOTE: This version of KixMacro.kix is NOT compatible with the
  9. ;       previous version! The temporary batch file will now be
  10. ;       written to a different location under a different name,
  11. ;       so you need to modify the CALL command line following
  12. ;       the invocation of the Kix script.
  13.  
  14.  
  15. ; Check command line parameters
  16. IF $KixMacro = ""
  17. 	GOTO Syntax
  18. ENDIF
  19.  
  20. ; Hide return codes
  21. REDIRECTOUTPUT( "NUL" )
  22.  
  23. ; Delete existing temporary batch file -- otherwise this
  24. ; script would append the result to the existing file.
  25. IF EXIST( "%TEMP%.\_KixMacro.bat" )
  26.     DEL "%TEMP%.\_KixMacro.bat"
  27. ENDIF
  28.  
  29. ; Determine the name of the variable: if not specified, use default
  30. IF $VarName = ""
  31. 	$VarName = "KixMacro"
  32. ENDIF
  33.  
  34. ; Create the temporary file and write the result to this file,
  35. ; or display an error message if the file cannot be created or
  36. ; opened with write access.
  37. IF OPEN( 1, "%TEMP%.\_KixMacro.bat", 5 ) = 0
  38.     EXECUTE( 'WRITELINE( 1, "SET $VarName=$KixMacro" )' )
  39.     REDIRECTOUTPUT( "" )
  40. $err = 0
  41. ELSE
  42.     REDIRECTOUTPUT( "" )
  43.     ? "Error opening temporary file, errorcode = " + @ERROR
  44. $err = 1
  45. ENDIF
  46. QUIT $err
  47.  
  48. :Syntax
  49. CLS
  50. ? "KixMacro.kix,  Version 2.00 for Windows"
  51. ? "Creates a temporary batch file to store Kix"
  52. ? "macro results in an environment variable"
  53. ?
  54. ? "Written by Rob van der Woude"
  55. ? "http://www.robvanderwoude.com"
  56. ?
  57. ? "Usage:"
  58. ? "    KIX32 KixMacro.kix $$KixMacro=@@macro [ $$VarName=env_var ]"
  59. ? "    CALL %%TEMP%%.\_KixMacro.bat"
  60. ? "Where:"
  61. ? "    '@@macro' is any valid Kix macro name"
  62. ? "    'env_var' is the name of the environment variable that"
  63. ? "    will hold the value of @@macro."
  64. ? "    If no $$VarName is specified, the default name KixMacro"
  65. ? "    will be used."
  66. ? "The second command calls the temporary batch file and stores"
  67. ? "the required value in the specified environment variable."
  68. ?
  69. ? "Press any key . . . "
  70. REDIRECTOUTPUT( "NUL" )
  71. GET $key
  72. REDIRECTOUTPUT( "" )
  73. CLS
  74. ? "Example:"
  75. ? "Executing the commands:"
  76. ?
  77. ? "    KIX32 KixMacro.kix $$KixMacro=@@DAY $$VarName=WeekDay"
  78. ? "    CALL %%TEMP%%.\_KixMacro.bat"
  79. ?
  80. ? "on friday will create a (temporary) batch file _KixMacro.bat"
  81. ? "(in the TEMP directory) containing one command line:"
  82. ? "SET WeekDay=Friday"
  83. ? "By calling this temporary batch file the day of the week is"
  84. ? "stored in the environment variable WeekDay."
  85. ?
  86. ? "See the Kix documentation for a list of available macros."
  87. ?
  88. ? "NOTE: This version of KixMacro.kix is NOT compatible with the"
  89. ? "      previous version! The temporary batch file will now be"
  90. ? "      written to a different location under a different name,"
  91. ? "      so you need to modify the CALL command line following"
  92. ? "      the invocation of the Kix script."
  93. ?
  94. ? "Press any key . . . "
  95. REDIRECTOUTPUT( "NUL" )
  96. GET $key
  97. REDIRECTOUTPUT( "" )
  98. QUIT 1
  99.  

page last modified: 2024-02-26; loaded in 0.0216 seconds