Sign in to follow this  
Followers 0
kokoilie

pass file to script?

11 posts in this topic

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!

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

kokoilie,

That does not take us very much further forward. :huh:

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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.

#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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

THANK YOU JOHN!!!

i just had to notice that the quote below wasn't part of your post and see if that var works

Share this post


Link to post
Share on other sites

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.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0