0

My goal is to automatically open a few specific files from calling a bash script.

P:\ = personal directory

Approach 1:

Example Code Below (filename: test):

    run "P:\Notepad++\notepad++.exe" "P:\test1.txt" "P:\test2.txt"

Question 1: When I do "./test" in the bash shell, it opens up Notepad++.exe with test1.txt and says "P:\test2.txt" doesn't exist. Create it?"

I have both test1.txt and test2.txt in the P:\ drive so I'm not sure why "test2.txt" doesn't exist. Is it only allowed to take one parameter?

Approach 2:

I tried to use an array approach, but it's not working.

    array = ("P:\test1.txt" "P:\test2.txt")
    run "P:\Notepad++\notepad++.exe" $array[*]

Now it opens up Notepad++.exe with none of the files open and says "P:\test2.txt)" doesn't exist. Create it?"

echo ${ARRAY[0]} Prints the entire array as a string... not sure why

SOLVED See answer below.

Thanks all who helped. Any elegant approach/solution is appreciated too :)

innerflow
  • 3
  • 3
  • [This question](https://stackoverflow.com/questions/32595421/is-it-possible-to-send-a-file-to-a-printer-with-a-batch-file) might give you a hint. – LMC Apr 26 '18 at 15:16
  • Hi Luis, Thank you for the comment! Definitely helpful. I would like to learn if it's possible to also maybe input keyboard shortcuts too like "ctrl+p" or "ctrl+o" through script. – innerflow Apr 26 '18 at 15:22
  • Bash scripts are intended to work without a GUI or GUI applications, everything happens inside a bash instance whether on a console or not. Some GUI apps can be scripted or interacted with, like KeePass does for example. All in all, you won't see 'ctrl+' shortcuts simulated on bash very often. – LMC Apr 26 '18 at 15:32
  • Ah I see, I'm fairly new to bash, but I'm guessing that it is incapable of automating the interaction (inputting keyboard command shortcuts to maybe run/compile things) with some GUI applications then? – innerflow Apr 26 '18 at 15:50
  • It's not meant for that. It's anyway an invaluable tool, give it a try, won't be disappointed :) . – LMC Apr 26 '18 at 17:34

1 Answers1

0

Not sure about the parameters of the run command in bash, but it does seem like there is a need for a filler if you want to open multiple files within any executable.

Solution:

run "P:\Notepad++\notepad++.exe" "P:\test1.txt" "P:\test2.txt" ""

The "" is some kind of filler but ends up allowing you to open notepad++.exe and the two text files.

This is for automation purpose :) Hope it helps other users!

powerzone3000
  • 2,838
  • 1
  • 13
  • 24
innerflow
  • 3
  • 3