I am new to Autoit and tried to do this:
Local $stest = "C:\Program Files (x86)\test\test.exe";
Local $sPath;
runS($stest);
Func runS(String $sPath) {
this.$sPath = $sPath;
If FileExists($stest) {
Run($stest , "", #SW_SHOWMAXIMIZED)
}
}
And get this error:
(6) : ==> Badly formated variable or macro.:
I am just trying to write a parameter as a path in the function...
No lines in AutoIt end with a ";". The ";" is used for commenting in
AutoIt.
If statements must have a “then” statement.
Nothing in AutoIt is opened or closed with the curly braces “{}”.
Most statements are closed with semantic words like EndIf, EndFunc and
Wend.
Here is what your code should look like:
;$g_sTest is global variable because it is being declared outside of a function.
Global $g_sTest = "C:\Program Files (x86)\test\test.exe"
runS($stest)
;$sPath will be a local variable because it is being declared inside of the fuction.
Func runS($sPath)
If FileExists($sPath) Then
Run($sPath, "", #SW_SHOWMAXIMIZED)
EndIf
EndFunc
Related
I'd like to include certain script only if it's present. Unfortunately #include is processed before the execution, so I can't make it conditional like this:
If FileExists(#ScriptDir & "\common.au3") Then
#include "common.au3"
EndIf
I tried to use Execute to evaluate the read file in place via Execute(ReadFile(...)). But that seems to only process single statements - I couldn't declare multiple functions for example.
Is there a different way to conditionally include another file?
Probably not a good design choice but if you really need to do somethin like this, try #OnAutoItStartRegister:
#OnAutoItStartRegister "_OnAutoItStart_CreateIncludes"
#include "include_collection.au3"
If IsDeclared("iExample_Common") Then
MsgBox(64, "", "Common.au3 exists")
Else
MsgBox(16, "", "Common.au3 wasnt included")
EndIf
MsgBox(0, "", "Your Script here")
Func _OnAutoItStart_CreateIncludes()
If StringInStr($CmdLineRaw, '-_OnAutoItStart_CreateIncludes', 1) Then Return
If FileExists(#ScriptDir & "\common.au3") And Not StringInStr(FileRead("include_collection.au3"), '#include "common.au3"') Then
FileWrite("include_collection.au3", '#include "common.au3"')
EndIf
$iPID = Run('"' & #AutoItExe & '" ' & $CmdLineRaw & ' -_OnAutoItStart_CreateIncludes', #WorkingDir, Default, 2)
While ProcessExists($iPID)
ConsoleWrite(StdoutRead($iPID))
Sleep(10)
WEnd
Exit
EndFunc ;==>_OnAutoItStart_CreateIncludes
Create an additional empty file "include_collection.au3" as well.
In this example, I created "commons.au3" containing a statement "$iExample_commons = 1234'.
Note: Once the file is included this way, it should not be deleted otherwise your script will fail again. This could probably be overcome too but at some point it will become very messy.
Maybe it's a better Idea to wrap a launcher around your application which will add/remove include lines before startup as needed.
as the title says, here is my code but its not working
; Get the parameter from open file dialog
GUICtrlSetData($locationtxt, FileOpenDialog("Select the program", '', "Supported files (*.exe;*.msi;*.reg;*.inf)|Executable Files (*.exe)|Microsoft Installer files (*.msi)|Registry files (*.reg)|Inf files (*.inf)", 3))
; store the value in a variable
$abc = GUICtrlRead($locationtxt)
; Run the program and pass the parameter value
Run("ussf.exe " & $abc )
; If i do it this way, its working but i want the parameter value from the open dialog not fixed
Run("ussf.exe C:\Users\project\ccsetup563.exe")
The second parameter for Run() is the working directory, not an argument for the program. I think you should be using ShellExecute(), or ShellExecuteWait() instead.
I am using Octave 5.1.0 on Windows 10 (x64). I am parsing a series of directories looking for an Excel spreadsheet in each directory with "logbook" in its filename. The problem is these files are created by hand and the filenaming isn't consistent: sometimes it's "LogBook", other times it's "logbook", etc...
It looks like the string passed as input to the dir function is case-sensitive so if I don't have the correct case, dir returns an empty struct. Currently, I am using the following workaround, but I wondered if there was a better way of doing this (for a start I haven't captured all possible upper/lower case combinations):
logbook = dir('*LogBook.xls*');
if isempty(logbook)
logbook = dir('*logbook.xls*');
if isempty(logbook)
logbook = dir('*Logbook.xls*');
if isempty(logbook)
logbook = dir('*logBook.xls*');
if isempty(logbook)
error(['Could not find logbook spreadsheet in ' dir_name '.'])
end
end
end
end
You need to get the list of filenames (either via readdir, dir, ls), and then search for the string in that list. If you use readdir, it can be done like this:
[files, err, msg] = readdir ('.'); # read current directory
if (err != 0)
error ("failed to readdir (error code %d): %s", msg);
endif
logbook_indices = find (cellfun (#any, regexpi (files, 'logbook'));
logbook_filenames = files(logbook_indices);
A much less standard approach could be:
glob ('*[lL][oO][gG][bB][oO][kK]*')
How can i Make any words into Autoit Commands?
This Code Works only if i type a Keyboard Hotkey combination, (but i want to type a word to execute the Autoit code.)
HotKeySet Example:
HotKeySet (“{F1}”, “calc”)
Func calc()
Local $iPID = ShellExecute (“calc.exe”)
EndFunc
Is there a Hotstringset Alternative.
i now in autohotkey you can make any words into Commands.
Autohotkey Languages example:
if i type calc it will execute the Autohotkey code.
:*:calc::
run calc.exe
return
With this you can make any words into Autoit Commands.
Step 1 - You can Download the HotStringSet.zip File Here. (included with the HotString.au3) HotKeySet vs HotStringSet
Step 2 - Unzip it + Copy manually the HotString.au3 to path C:\Program Files (x86)\AutoIt3\Include
Step 3 - Now your are ready to use HotStringSet in any Autoit Script.
You can Type on your keyboard any text, for example in Wordpad : Type calc+Space and it will run the Calculator and if you Type kbc+Space it will replace the text kbc into keyboard control and if you Type pi+Space it will replace the text pi into Symbol pi.
Write this Autoit Code.
#include <HotString.au3>
HotKeySet ('{F1}', 'quit')
HotStringSet('kbc{SPACE}', replace1)
HotStringSet('pi{SPACE}', replace2)
HotStringSet('calc{SPACE}', replace3)
Func quit()
Exit
EndFunc
Func replace1()
;MsgBox(0,'','You did typed kbc! :)')
send ('{BS 4}keyboard control ') ; replace [kbc] into [keyboard control]
EndFunc
Func replace2()
;MsgBox(0,'','You did typed pi! :)')
send ('{BS 3}{ASC 960} ') ; replace [pi] into [symbol p]
EndFunc
Func replace3()
;MsgBox(0,'','You did typed calc! :)')
Local $iPID = ShellExecute ('calc.exe') ; If you type calc it wil run the application calculator.
EndFunc
While 1
Sleep(10)
WEnd
I have some code which appends text over an existing .txt file , from within R as following :
write("puts 'hellow world '", file = "C:\\Ruby22-x64\\bin\\elt.rb",
append = TRUE, sep = " ")
setwd("C:/Ruby22-x64/bin/")
test<-system("ruby elt.rb",intern=TRUE) # this will return "hellow world" from ruby interpreter
My question is: after appending the .rb file and running it, how can i remove the "puts 'hellow world '" string from the .rb file, and return it to its initial state?
I tried to look for many functions, but couldn't find any function which can undo the write function.
Just found out a wonderful gist that does the Job : https://gist.github.com/mages/1544009
gist:1544009