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

4

18

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?

Sudd answered 2/5, 2013 at 18:1 Comment(0)
I
28

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.

Interpretative answered 2/5, 2013 at 20:25 Comment(2)
Thanks for the reply. So this is a good idea, but when I type in >photoshop "path\to\file.pdf" it opens Photoshop, but does not open the pdf. Photoshop.exe is in my path environment variables. Have you successfully used this technique to open a PDF in Photoshop on your computer? Can you think of any reason as to why that command would open the software but not the PDF?Sudd
@Sudd specifying a valid path to file opens fine for me, photoshop will just open without opening the file if the path is not valid - so I would double check the path is correctThrombocyte
S
2

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
Strident answered 1/6, 2014 at 19:50 Comment(0)
O
1

You can do it by using the start command:

start <program-name> <file-path>

In your case, you would have to do something like this:

start photoshop D:\open.pdf
Octopod answered 28/2, 2021 at 14:42 Comment(0)
E
0

Unfortunately, the current version of Photoshop doesn't support this operation out of the box. You can open the program: start "path_to_photoshop.exe", but there is no way to pass it a file to open. If you really want to do it, you will need to get something like this: https://www.eulanda.eu/en/access-photoshop-api-via-powershell-script. Sorry, I wish I had a better answer, especially since I wanted to be able to do this for a program I was working on.

Evangelistic answered 14/5, 2020 at 1:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.