Batch file to open 3 programs and a folder - I'm almost there - excel

Batch file Requirement;
I need to open 1) WindSailor 2) Addons Linker 3) folder (drive) "O" and 4) Excel-01. MSFS.xlsm.
The issue is - when Excel opens, it is not set to autosave via OneDrive. I have to set it to autosave manually after it opens.
I have 1 .bat file that opens 1, 2 and 3 perfectly.
#echo off
start "" "C:\Users\Dad\Desktop\WindSailor"
start "" "C:\Users\Dad\Desktop\Addons Linker"
start "" "O:\"
And I have a second .bat file that opens Excel perfectly - all set for autosave via OneDrive.
#echo off
set params=%*
start excel "E:\OneDrive\03. Excel\02. Flight Sim\01. MSFS\01. MSFS.xlsm" /e/%params%
But when I combine the two, Excel opens but not set to autosave...
#echo off
start "" "C:\Users\Dad\Desktop\WindSailor"
start "" "C:\Users\Dad\Desktop\Addons Linker"
start "" "O:\"
set params=%*
start excel "E:\OneDrive\03. Excel\02. Flight Sim\01. MSFS\01. MSFS.xlsm" /e/%params%
I have tried countless variations - what am I missing ?

Related

How to remove dead files from Open Recent list in Sublime Text 3?

In Sublime Text 3 if I go to:
MENU: File>Open Recent
There are files in that list which are no longer available.
How can I clean that list of dead files?
I don't want to clear the full list, just the dead ones.
Note: I've followed How to increase number of recent files in Sublime Text 3? to get 30 recent files showing in this menu.
Following this post over on the Sublime Forum it can be done by editing the Session.sublime_session file.
For example: I'd edited etc/hosts so I could block myself from watching youtube, but with it being in the recent files list in Sublime it's easy to unblock myself thus I wanted to remove /etc/hosts from my recent file list in Sublime (ST3).
My copy of Sessions.sublime_session is in ~/.config/sublime-text-3/Local/ from which I deleted all lines containing etc/hosts.
The only caveat is that you can't edit that file using Sublime, Sublime should not be running, I used a different text editor.
Final caveat this is the solution for linux, and ST3, for windows and mac I'm guessing there's something similar.
I found out how to do this using this python script here:
https://github.com/STealthy-and-haSTy/SublimeScraps/tree/master/session_cleaner
I don't want to post the python code as I don't have permission to do so but that has been up on GitHub for a couple of years so there should be no worries of it disappearing anytime soon.
I've written a batch file that will start the python file, see the code below. Just name it RunSessionCleaner.cmd and place this in the same folder as the sublime_session_clean.py file.
#echo off & title %~nx0 & color 5F & chcp 65001 >NUL
rem Based on this thread here: https://stackoverflow.com/a/13351373
goto :MY_ROUTINE
:CMD_SIZE
chcp 850 >NUL & set "uiWidth=%1" & set "uiHeight=%2"
mode %uiWidth%,%uiHeight%
if %4==TRUE (set /a "uiHeightBuffer=uiHeight+%3")
if %4==TRUE (powershell.exe -ExecutionPolicy Bypass -Command ^
"&{$H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=%uiWidth%;$B.height=%uiHeightBuffer%;$W.buffersize=$B}")
if %4==FALSE (powershell.exe -ExecutionPolicy Bypass -Command ^
"&{$H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=%uiWidth%;$B.height=%uiHeight%;$W.buffersize=$B}")
chcp 65001 >NUL & goto :EOF
:MY_ROUTINE
call :CMD_SIZE 60 7 222 TRUE
title Cleaning folders, files and projects...
echo Cleaning folders, files and projects...
:: Full path to data folder W:\Apps (Portable)\Sublime Text\Data
:: Full path to python.exe W:\Apps (Portable)\Sublime Text\Data\Packages\User\SessionCleaner\python\python.exe
:: Full path to sublime_session_clean.py W:\Apps (Portable)\Sublime Text\Data\Packages\User\SessionCleaner\sublime_session_clean.py
:: Or like I have done use a relative directory to the Data folder
:: The SsssionClearner.py file is located in: W:\Apps (Portable)\Sublime Text\Data\Packages\User\SessionCleaner
::
:: Change this line below to suit your needs.
".\python\python.exe" "sublime_session_clean.py" --data-dir "..\..\..\..\Data" --workspaces --files --folders
echo/
goto :EXIT_ROUTINE
:EXIT_ROUTINE
rem call :CMD_SIZE 100 10 222 FALSE
title Exiting routine...
echo Exiting routine...
set /p "=" <NUL &
ping localhost -n 3 >NUL & exit
exit
Change line 24 of the code above to suit your paths. You can just use relative paths here like I have done so you can do that too.
This batch file can be clicked on or set up in Task Scheduler to start up when the PC does to clean out all the non-existent files or workspaces.
Please note, Sublime Text needs to be closed in order for this to work.

Searching in Finder from Selection

Usually I get an excel spreadsheet with dozens of filenames, for which I then need to go and search individually.
Spreadhseet
Is there a way that I could simply:
Select All filenames in e.g. row A of Excel,
then Search for all these files on "This Mac"
then Copy all found files into the New Folder on the Desktop
So far I've tried the first part of searching and this is what i get :a)
Automator with Variable. But the problem is, it only searches for 1 file from selection
b)
Automator with Shell Script (Copy to Clipboard > Open Finder > CMD+F (to highlight Search dialog) > CMD+V). It opens a new Finder window, but it doesn't paste the clipboard into search dialog
c) /usr/bin/pbcopy
on run {input, parameters}
tell application "System Events"
keystroke "f" using {command down}
keystroke "v" using {command down}
end tell
return input
end run`
End result, is same as option b). I was planning to run this in Automator as a 'Service', which I could later assign to Keyboard Shortcut.
I am pretty sure there should be a simple shell option for this - any advice would be much appreciated.
I made a bash script that does what you want. You would basically select a bunch of filenames in Excel, or any other app, and copy them to the clipboard with ⌘C. After that you need to run the script and it will take items from the clipboard and search for TIFF or JPEG images that match that name and copy them to a directory on your Desktop called Selected Files:
#!/bin/bash
# Get contents of clipboard into bash array
files=( $(pbpaste) )
# Create output directory - no checks for already existing or already containing files
OUTDIR="$HOME/Desktop/Selected Files"
mkdir -p "$OUTDIR"
# Iterate through fetching files
for ((i=0;i<${#files[#]};i++)) ; do
name=${files[i]}
result=$( mdfind "kMDItemDisplayName == \"${name}.*\" && (kMDItemKind==\"TIFF image\" || kMDItemKind==\"JPEG image\")" )
if [ -f "$result" ]; then
echo $name: $result
cp "$result" "$OUTDIR"
else
echo ERROR: Searched for: $name, found $result
fi
done
I am not sure of your level of familiarity with bash, so you may be able to ignore the following...
Make a new directory for your own scripts:
mkdir -p $HOME/scripts
Save the above script in that directory with filename:
$HOME/scripts/gather
Make the script executable by typing this into Terminal:
chmod +x $HOME/scripts/gather
Edit your login profile ($HOME/.profile) and add your $HOME/scripts directory to your PATH:
export PATH="$PATH":$HOME/scripts
Then start a new Terminal and you can use any script that you have saved in $HOME/scripts without needing to specify the full path to it, e.g.:
gather
Following information kindly contributed by #user3439894 in comments section, as I am out of my depth on this aspect...
To use a keyboard shortcut, you'd have to create an Automator "Service workflow" with a "Run Shell Script" action, which you can assign a keyboard shortcut to under: System Preferences > Keyboard > Shortcuts > Services

String captured from window text invalid as pathname (AutoIT)

I am running into a problem automating an installation procedure. I want to install a program, and then patch it with a custom UserPatch to remove some glitches.
The UserPatch executable must be run from the installation directory, so I must retrieve this address from the installer. Then, after the program is installed, the script must copy the UserPatch file to the installation directory, and run it from there.
I retrieve the pathname as shown below. The script copies the raw text from the window, which I strip down to just the line containing the pathname.
WinActivate("Dir browse box title")
$InstallDir = WinGetText("Dir browse box title")
$split = StringSplit( $InstallDir, "&Path", 1)
$InstallDir = $split[2]
$split = StringSplit( $InstallDir, "&OK", 1)
$InstallDir = $split[1]
ControlClick("Dir browse box title", "&Drives", "[Class:CButtonClassName; INSTANCE:2]")
Sleep(100)
When printing "$InstallDir" after the above procedure, it shows exactly what I want it to be: "C:\Program Files (x86)\Path to\Installation folder" (without '"').
The problem is this: It doesn't copy the file when I run the code snippet below. It does work when I hardcode the pathname (commented in the code below), but not when using the $InstallDir variable as retrieved by the code snippet above.
; Install the UserPatch
; $InstallDir = "C:\Program Files (x86)\Path to\Installation folder"
$UserPatchName = "SetupAoC.exe"
FileCopy($UserPatchName, $InstallDir & "\" & $UserPatchName)
Run($InstallDir & "\" & $UserPatchName)
WinWait("SetupAoC - Feature Update Tool")
ControlClick("SetupAoC - Feature Update Tool", "Install", "[Class:DirectUIHWND; INSTANCE:1]")
Send("{SPACE}")
Sleep(2000)
WinClose ("SetupAoC - Install Complete")
WinClose ("SetupAoC - Feature Update Tool")
I've got the feeling that I'm missing something obvious, but I really can't tell what the problem is? Any ideas?
Thanks in advance!
EDIT in reply to comments:
After
$InstallDir = WinGetText("Dir browse box title")
the value of $InstallDir is
&Drives
C:\ Crucial M500
&Folders
&Path
C:\Program Files (x86)\Path to\Installation folder
&OK
&Cancel
I then use StringSplit, which creates an array of strings, separated by the specified delimiter.
OK, problem eliminated.
The problem was that my "C:\path...." string was preceded and trailed by two #CRLF characters (new lines). These were also present in the raw data that I copied from the window, as I didn't include them in my delimiters.
I didn't notice them when printing the output, as they're white-space. I found out when writing the $InstallDir variable to a file, in a desperate attempt.
Anyway, Solved with
$InstallDir = StringReplace($InstallDir, #CRLF, "")
Thanks for the tips, #Matrix and #McBarby!

Move 300 images from a folder (contains 800 images) to another based on file name list

I need to move 300 images from a folder (contains 800 images) to another folder. The file name list of these 300 images are available in the excel format. Is it possible to move them via programming instead of search the file and move it one by one? Our IT told me he can't separate these files. Do you have any solution? Many thanks in advance!!!
Here's one way of doing this - I am assuming you are on Windows. First, save text file called ListOfImages.txt that contains the names of the images you wish to move - put one image on each line and include the extension. Then, save the following into a file called movefiles.cmd:
#echo off
set Source=C:\Users\YourName\Desktop\moving\MovingFrom
set Target=C:\Users\YourName\Desktop\moving\MovingTo
set FileList=C:\Users\YourName\Desktop\moving\ListOfImages.txt
echo.
if not exist "%Source%" echo Source folder "%Source%" not found & goto Exit
if not exist "%FileList%" echo File list "%FileList%" not found & goto Exit
if not exist "%Target%" md "%Target%"
for /F "delims=" %%a in ('type "%FileList%"') do move "%Source%\%%a" "%Target%"
:Exit
echo.
echo press the Space Bar to close this window.
pause > nul
You will want to change the variables for Source, Target, and FileList to match where you have those folders and the ListOfImages.txt on your machine. After you have saved this file (make sure it has the .cmd extension, you should be able to double-click it and it will run the commands in your Command Prompt.
For example, say my MovingFrom folder contains the following:
And I only want to move Image1.png and Image2.png -- then my ListOfImages.txt file would like this:
After running moveFiles.cmd (provided I have changed the necessary variables to point to the right folders/places on my machine), my MovingTo folder should contain the following:
Notice that Image2.png was not moved because it was not listed in the ListOfImages.txt text file.

Refresh excel workbook from command line

I have an excel workbook in which there is data from multiple text files.
The text files are created in a .bat script.
I would like to refresh the workbook in the script right after creating the files.
Does anyone know a command that can do that?
Thanks!
For command line refresh (scheduled by Windows task scheduler) I ended up using this open source application: https://github.com/alapolloni/ExcelRefresh. Note that Excel needs to be installed on client for this to work.
You can specify what to update, for example "macros", "pivot tables", "Queries" or simply "all".
Together with this nice tool "WasFile" from https://www.horstmuc.de/wbat32.htm you can check the age to avoid unnecessary excel-refreshes.
For example, a batch file:
set file1="c:\Tmp\refreshMe.xlsx"
ECHO.
echo ----- %File1% -----------------------------
C:\Test\WasFile.exe %file1% modified not after today-1
if %errorlevel%==0 (echo TRUE: Older than
Goto Next1
)
if %errorlevel%==1 (
echo FALSE: Not older
goto Skip1
)
if %errorlevel%==255 (
Echo ERROR
goto Error
)
:Next1
Echo ### Update START ....
C:\test\ExcelRefresh.exe -d -a -f %file1%
Echo ### Update END ....
echo.
I don't think excel has CLI, but you can use VBS - there is example of importing data from excel spreadsheet using vbs: http://www.gregthatcher.com/Papers/VBScript/ExcelExtractScript.aspx but it's possible to do this in reverse direction too.

Resources