Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a file from the command line with a specified program?

I would like to open a PDF in Photoshop from the command line. My current issue right now is that the default application for opening PDFs is Adobe Acrobat. I'm wondering if there is any parameter I can pass to specify which program to use when opening a file.

In other words, I want to emulate the option of "Open-with" when you right-click a file to open it with the non-default application, but from the command line.

I do not want to change the default application for PDFs to be Photoshop.

Any ideas?

like image 668
csterling Avatar asked May 02 '13 18:05

csterling


People also ask

How do you open a file from the command-line with a specific program?

Type "start [filename.exe]" into Command Prompt, replacing "filename" with the name of your selected file. Replace "[filename.exe]" with your program's name. This allows you to run your program from the file path.

How do you open a file with a specific program Linux?

Right-click the file and select Properties. Select the Open With tab. Select the application you want and click Set as default. If Other Applications contains an application you sometimes want to use, but do not want to make the default, select that application and click Add.

How do I view a file in command prompt?

Navigate to the directory containing the folders you wish to appear in your list. Click in the address bar and replace the file path by typing cmd then press Enter. This should open a black and white command prompt displaying the above file path. Type dir /A:D.

How do I get to program files in terminal?

While in the command prompt type "cd\", then enter. From there type "cd\program" then hit the tab button until you see "c:\program files (x86)", then hit enter.


2 Answers

All you need to is provide the filename as a command line argument:

photoshop <path to file>

(<path to file> needs to be quoted if it contains spaces)

For example:

photoshop "C:\Users\csterling\Documents\some document.pdf"

If the directory containing photoshop.exe isn't in your Path environment variable, you'll need to provide the full path:

"C:\Program Files\Adobe\Photoshop\photoshop" "C:\Users\csterling\Documents\some document.pdf"

This isn't a feature of the command prompt, it's a feature of the executable, i.e. photoshop.exe has to be programmed to accept a file to open as a command line argument. Fortunately, it is, as are the majority of Windows applications that operate on files.

like image 75
Adi Inbar Avatar answered Sep 27 '22 22:09

Adi Inbar


In case you want this to work with relative path in PowerShell, here is the script:

function photo
{
   $the_filename=resolve-path $args[0]
   photoshop $the_filename
}

Then you can just type:

cd C:\Users\csterling\Documents
photo mypic.jpg
like image 26
Seperman Avatar answered Sep 27 '22 22:09

Seperman