kokoilie Posted November 11, 2012 Share Posted November 11, 2012 Is there a way to pass a file to the script at startup? I mean the same way as if you open a .bmp file and it starts paint opening that file. There is no code of what i did by now because i don't know if there is a way to do it but any advice will be appreciated. Thanks in advance! Link to comment Share on other sites More sharing options...
Developers Jos Posted November 11, 2012 Developers Share Posted November 11, 2012 (edited) Do you mean whether it is possible to associate a unique file extension to a compiled script? Then the answer is yes ..... else I don't understand what you are asking. Jos Edited November 11, 2012 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
JohnOne Posted November 11, 2012 Share Posted November 11, 2012 What Jos said, the only other possibility I can think you might mean is passing the name/path of a file to work with when you start, and that is done via command line . Run("pathtocompiledscript.exe pathtothefile.ext") In your compiled script you will need to use the built in variable arrray "$CmdLine" <- help file. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
kokoilie Posted November 13, 2012 Author Share Posted November 13, 2012 Not just to associate a specific file extension but to receive a variable containing it's path for opening when the script is started from such file. Right now i have a button to open a file manually but want to make it like other programs. John, i have no idea what you mean and how this is going to help me. Also i can't seem to find that "$CmdLine" you mentioned Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 13, 2012 Moderators Share Posted November 13, 2012 kokoilie, That does not take us very much further forward. As you obviously already have a script with a button, why not post it so that we can see what you are trying to do - then your question might become clearer. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Bert Posted November 13, 2012 Share Posted November 13, 2012 I think I know what you are asking for. You can use an INI file to do what you want. Look in the Help File for INIRead and INIWrite. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
kokoilie Posted November 13, 2012 Author Share Posted November 13, 2012 For now it's not really opening any files just having a string containing the pathname of a file because if i have this information about the file i can read/write it at any time. I'll post the script anyway. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt ("MustDeclareVars", 1) Func _loadlang () Global Const $lnofile = IniRead ("language.ini", "language", "nofile", "No file opened") Global Const $lidlenf = IniRead ("language.ini", "language", "idlenf", "Idle (no file opened): Please open an archive or create a new one.") Global Const $ltitle = IniRead ("language.ini", "language", "title", "AutoIt Archiver") Global Const $labout = IniRead ("language.ini", "language", "about", "Program for archiving files without compression V.") Global Const $lfo = IniRead ("language.ini", "language", "fo", "File opened:") Global Const $lfns = IniRead ("language.ini", "language", "fns", "File not saved. Do you want to save before closing it?") Global Const $ltn = IniRead ("language.ini", "language", "tn", "Create new file") Global Const $lto = IniRead ("language.ini", "language", "to", "Open archive") Global Const $ltco = IniRead ("language.ini", "language", "tco", "Close opened archive") Global Const $lts = IniRead ("language.ini", "language", "ts", "Save archive") Global Const $ltsa = IniRead ("language.ini", "language", "tsa", "Save archive as") Global Const $lti = IniRead ("language.ini", "language", "ti", "Import files in archive") Global Const $lte = IniRead ("language.ini", "language", "te", "Export all files from archive") Global Const $lta = IniRead ("language.ini", "language", "ta", "About the program") Global Const $ltl = IniRead ("language.ini", "language", "tl", "List of files in the opened archive") ; EndFunc _loadlang () Global $gui, $msg = -1, $content = $lnofile, $saved = True, $tip = $lidlenf, $clist, $file = "", $ofile = "", $fileh = -1, $ask = 0, $mouse, $otip = $lidlenf, $data, $array, $fread Global $bopen, $bnew, $bsave, $bsaveas, $bimport, $bexport, $bclose, $ctip, $babout $gui = GUICreate($ltitle, 900, 400) $bnew = GUICtrlCreateButton ("New", 5, 2, 50, 20) $bopen = GUICtrlCreateButton ("Open", 60, 2, 50, 20) $bclose = GUICtrlCreateButton ("Close", 115, 2, 50, 20) $bsave = GUICtrlCreateButton ("Save", 170, 2, 50, 20) $bsaveas = GUICtrlCreateButton ("SaveAs", 225, 2, 50, 20) $bimport = GUICtrlCreateButton ("Import", 280, 2, 50, 20) $bexport = GUICtrlCreateButton ("Export", 335, 2, 50, 20) $babout = GUICtrlCreateButton ("About", 390, 2, 40, 20) $ctip = GUICtrlCreateLabel ($tip, 435, 5, 460, 20) $clist = GUICtrlCreateEdit ($content, 5, 30, 890, 365) GUICtrlSetState ($bclose, $GUI_DISABLE) GUICtrlSetState ($bsave, $GUI_DISABLE) GUICtrlSetState ($bsaveas, $GUI_DISABLE) GUICtrlSetState ($bimport, $GUI_DISABLE) GUICtrlSetState ($bexport, $GUI_DISABLE) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() $mouse = GUIGetCursorInfo ($gui) ;ToolTip ($mouse[4]) Select Case $mouse[4] = 0 $tip = $otip Case $mouse[4] = 11 $tip = $otip Case $mouse[4] = 3 $tip = $ltn Case $mouse[4] = 4 $tip = $lto Case $mouse[4] = 5 If $file = "" Then $tip = $otip Else $tip = $ltco EndIf Case $mouse[4] = 6 If $file = "" Then $tip = $otip Else $tip = $lts EndIf Case $mouse[4] = 7 If $file = "" Then $tip = $otip Else $tip = $ltsa EndIf Case $mouse[4] = 8 If $file = "" Then $tip = $otip Else $tip = $lti EndIf Case $mouse[4] = 9 If $file = "" Then $tip = $otip Else $tip = $lte EndIf Case $mouse[4] = 10 $tip = $lta Case $mouse[4] = 12 If $file = "" Then $tip = $otip Else $tip = $ltl EndIf EndSelect If GUICtrlRead ($clist) <> $content Then GUICtrlSetData ($clist, $content) EndIf If GUICtrlRead ($ctip) <> $tip Then GUICtrlSetData ($ctip, $tip) EndIf If $saved = True And GUICtrlGetState ($bsave) = 80 Then GUICtrlSetState ($bsave, $GUI_DISABLE) ElseIf $saved = False And GUICtrlGetState ($bsave) = 144 Then GUICtrlSetState ($bsave, $GUI_ENABLE) EndIf If $file <> "" And GUICtrlGetState ($bclose) = 144 Then GUICtrlSetState ($bclose, $GUI_ENABLE) GUICtrlSetState ($bsaveas, $GUI_ENABLE) GUICtrlSetState ($bimport, $GUI_ENABLE) GUICtrlSetState ($bexport, $GUI_ENABLE) $tip = $lfo & " " & $file $otip = $tip ElseIf $file = "" And GUICtrlGetState ($bclose) = 80 Then GUICtrlSetState ($bclose, $GUI_DISABLE) GUICtrlSetState ($bsaveas, $GUI_DISABLE) GUICtrlSetState ($bimport, $GUI_DISABLE) GUICtrlSetState ($bexport, $GUI_DISABLE) $tip = $lidlenf $otip = $tip EndIf Select Case $msg = $bnew $file = @ScriptDir & "NewArchive.aia" $content = "" $saved = False Case $msg = $bopen $ofile = FileOpenDialog ($ltitle, @ScriptDir, "AIArchives (*.aia)", 3, "", $gui) If $ofile <> "" Then $saved = False $file = $ofile _open (False) $ofile = "" EndIf Case $msg = $bclose If $saved = False Then $ask = MsgBox (3, $ltitle, $lfns, 0, $gui) If $ask = 6 Then savefile(False) $saved = True $fileh = -1 $file = "" ElseIf $ask = 7 Then $saved = True $fileh = -1 $file = "" EndIf Else $file = "" $saved = True $content = $lnofile $fileh = -1 EndIf Case $msg = $bsave savefile (False) $saved = True Case $msg = $bsaveas savefile (True) Case $msg = $bimport $content = _open (True) Case $msg = $bexport ;_open (False) Case $msg = $babout MsgBox (0, $ltitle, $labout & " Alpha 0.1", 0, $gui) Case $msg = $GUI_EVENT_CLOSE If $saved = False Then $ask = MsgBox (3, $ltitle, $lfns, 0, $gui) If $ask = 6 Then savefile (False) $saved = True $fileh = -1 $file = "" Exit ElseIf $ask = 7 Then $saved = True $fileh = -1 $file = "" Exit EndIf Else Exit EndIf EndSelect WEnd Func savefile ($flag = False) If $flag = False Then $fileh = FileOpen ($file, 2) FileWrite ($fileh, $data) FileFlush ($fileh) Else $ofile = FileSaveDialog ($ltitle, @ScriptDir, "AIArchives (*.aia)", 18, "NewArchive.aia", $gui) If $ofile <> "" Then $file = $ofile $fileh = FileOpen ($file, 2) FileWrite ($fileh, $data) FileFlush ($fileh) $ofile = "" $saved = True EndIf EndIf EndFunc Func _open ($flag = False) Local $i = 0 If $flag = False Then ;open $data = $fread Else ;import $ofile = FileOpenDialog ($ltitle, @ScriptDir, "AIArchives (*.aia)", 7, "", $gui) If @error Then $ofile = "" Return "" EndIf $array = StringReplace ($ofile, "|", @CRLF) $ofile = "" Return $array EndIf EndFunc Scullion, i know how to use ini files even in this script i'm using one for locale (change language) option Link to comment Share on other sites More sharing options...
JohnOne Posted November 13, 2012 Share Posted November 13, 2012 When you associate an extension with your program, you double click that file.ext and your program will open. Is that what you want? if so, then when you do that, the name of the file you clicked will be in an array named $CmdLine[1] you can use that in your script. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
kokoilie Posted November 13, 2012 Author Share Posted November 13, 2012 THANK YOU JOHN!!! i just had to notice that the quote below wasn't part of your post and see if that var works Link to comment Share on other sites More sharing options...
guinness Posted November 13, 2012 Share Posted November 13, 2012 A couple of points, look at _ShellFile in my signature and try to avoid using Global scope within a function, this should be only reserved for Local. If you want to declare a Global variable that can be seen throughout the program, then declare at the top of the script. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
kokoilie Posted November 17, 2012 Author Share Posted November 17, 2012 Guinness, I've understood how to use the $cmdline and made it like you used it in your example so this topic is solved.(actually i read your post after i made it) And yes i can omit the function but why should i avoid using global in functions? I am declaring constants in it not variables, how else i can get their values except assigning them out of the function? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now