Search code examples
excelautoit

autoIT copy most recent filepath to clipboard


Hello I am writing a script that will open the windows 10 camera, then display the most recent image when I close the camera then with a GUI, ask the user if the image is okay. If they select yes then the script would copy the filepath to the clibpoard and then be able to past this filepath into a Microsoft Excel cell. I have everyhting working how I want it to until the point where I need the filepath to be copied to the clipboard. Here is my code so far.

#include <MsgBoxConstants.au3>

Camera()

Func Camera()
    ; Execute Camera and wait for Camera to close
    Local $iPID = ShellExecuteWait("explorer.exe", "shell:AppsFolder\Microsoft.WindowsCamera_8wekyb3d8bbwe!App")
    Sleep(3000)
    WinWaitClose("Camera")
EndFunc

#include-once
#include <Array.au3>
#include <File.au3>
#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <Process.au3>

$dst        = "C:\Users\Cex\Pictures\Camera Roll" ; specify folder
$a_FileList = _FileListToArray2()

_ArraySort($a_FileList, 1, 1, $a_FileList[0][0], 1)
ShellExecute($a_FileList[1][0])

Func _FileListToArray2($s_Mask='*')
    $h_Search   = FileFindFirstFile($dst & '\' & $s_Mask)
    $s_FileName = FileFindNextFile($h_Search)

    If Not @error Then
        Dim $a_File[100][2]

        While Not @error
            If StringInStr($s_FileName,'.',0,-1) Then
                $s_FullName    = $dst & '\' & $s_FileName
                $a_File[0][0] += 1

                If $a_File[0][0] >= UBound($a_File) Then
                    ReDim $a_File[$a_File[0][0] * 2][2]
                EndIf

                $a_File[$a_File[0][0]][0] = FileGetLongName($s_FullName)
                $a_File[$a_File[0][0]][1] = FileGetTime($s_FullName,0,1)
            EndIf
            $s_FileName = FileFindNextFile($h_Search)
        WEnd

        ReDim $a_File[$a_File[0][0] + 1][2]

        Return $a_File
    EndIf

    Return ''
EndFunc

#include <GUIConstantsEx.au3>
#include <IE.au3>

WinWaitActive("Photos", "")

Local $qGUI   = GUICreate("Example", 200, 125, 1000, 200)
                GUICtrlCreateLabel("Are you happy with this image?", 30, 30)
Local $bYes   = GUICtrlCreateButton("Yes", 6, 60, 85, 25)
                GUICtrlSetOnEvent($bYes, "xYes")
Local $bNo    = GUICtrlCreateButton("Yes", 107, 60, 85, 25)
                GUICtrlSetOnEvent($bNo, "xNo")
Local $bClose = GUICtrlCreateButton("Close", 57, 90, 85, 25)

GUISetState(@SW_SHOW, $qGUI)

While 1
    Switch GUIGetMsg()
        Case $bYes
            bYes()
            GUIDelete($qGUI)
            Exit

        Case $bNo
            bNo()
            GUIDelete($qGUI)
            Exit

        Case $bClose, $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func bYes()
    _RunAU3("YesTest.au3")
EndFunc

Func bNo()
    _RunAU3("NoTest.au3")
EndFunc

Func _RunAU3($sFilePath, $sWorkingDir = "", $iShowFlag = @SW_SHOW, $iOptFlag = 0)
    Return Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sFilePath & '"', $sWorkingDir, $iShowFlag, $iOptFlag)
EndFunc

Like I said I am looking to copy the filepath of the most recent photograph and then copy it to the clipboard which will then be pasted into a cell in excel. I have limited coding knowledge so there are probably many bad points to my code but I have just been learning as I go along so if anyone can help me please do not confuse me however, if you have to, then all help is appreciated!


Solution

  • AutoIT has build in functions for the clipboard, such as ClipPut and ClipGet.

    ClipPut($filepath)
    

    which would be in your case

    ClipPut($a_FileList[1][0])