I'm trying to create an Illustrator file from PowerShell. I can create a new .ai file, but Illustrator can't open it.
Here is what I tried:
PS C:\Users\my.name> Invoke-Item "C:\Program Files\Adobe\Adobe Illustrator 2023\Adobe Illustrator 2023.lnk"
PS C:\Users\my.name> New-Item -Path "C:\Users\my.name\Documents\scripting\testfile.ai"
When I go to the file location, the file exists as a .ai document, but I get this error when I try to open it:
Can't open the illustration. The file may be read only, or the file is in use by another application, or you do not have the required permissions. Please save the document with a different name, or in a different folder or directory.
Anyone know why this is happening? Thanks!
Currently your first command just starts illustrator, nothing else. The second just creates an empty file.
You'll probably want to create a new .ai file manually somewhere as a template, then copy it as needed:
Copy-Item "C:\folder\template.ai" "C:\folder\testfile.ai"
Once you have a new testfile, then you can open it in illustrator like so, as long as your default program for ai files is correct:
Start-Process "C:\folder\testfile.ai"
Related
Can a Windows batch file determine its invoked filename when invoked through a shortcut?
For example, I create real.bat, and create its shortcut named phony.bat (.lnk?)
And invoke phony by double-click on it.
Can this batch file detect the name phony.bat instead of real.bat?
Of course I can just copy it to another name, but when I edit one of them, I have to manually sync the content to all files.
The question is related to Can a Windows batch file determine its own file name?, but different.
As in your you mentioned that you've created the shortcut I assume you can create the with any properties you want.
So right click on your lnk file and change the the target line to:
C:\Windows\System32\cmd.exe /c "set "lnk_call=1"&"C:\PATH\TO\your.bat" "
This will change the icon of the link so to set back to batch file cog click on change icon and find the bat file icon in :
%SystemRoot%\System32\SHELL32.dll
Finally in your bat put this line:
if defined lnk_call echo triggered from lnk file
the lnk_call now can be used to determine if your file is called from double clicking on a .lnk file. I don't think it is possible to detect this from a shortcut that anyone else created.
Oh yeah, I found hardlink useful in this case:
mklink /h <link-name> <source-file>
I can create many hardlinks with different name, and they all points to the same file, so I can freely edit any one of them without manually sync their content.
I have a symlink named example.avi that points to a real example.avi video file. When a program tries opens the symlink, it really opens the video file. But now I would like execute a command line whenever a program tries to open the symlink file.
Is that possible?
ps: windows
No, there is no built-in way of creating a symlink or other file system object that causes a command to be executed when it is opened by an application.
It should in principle be possible to do this with a file system filter driver. But that's very complicated. I believe there are some third-party tools to simplify this sort of task, but I don't have any experience with them.
While I am clearly ignorant on the subject of symlinks in Windows (see my comments on your question). I just played with it and proved that you could basically do this by symlinking to a wrapper for your avi. I.e. symlink to an exe or a batch file, etc. which does what you want and then opens the avi. Here's a test I ran with txt files and notepad:
Create a file called test.txt with some text. Create a file next to it called test.bat. Here's the batch:
notepad test.txt
When you run the batch, it just opens the txt in notepad.
Then I added a symlink:
mklink test2.txt test.bat
Now, when I type test2.txt in the command prompt, or double click on it, it runs the batch and opens the test.txt file. Obviously, you can use the same basic logic. It doesn't, however, fire the batch off when I open the symlink in Notepad++. It just opens to batch for editing instead.
Of course, maybe you don't want a second file, in which case you need to literally embed your avi in some wrapper. I guess we ned to know more about what you want to do. It sounds like an attempt at malware hidden in a video to me...
I have a folder of .doc files I would like to convert to .txt format. How can I do that using LibreOffice's command line mode in Windows 7? The files are located in C:\Temp\Test.
Here is how I handled this task using Windows PowerShell
Note: before using LibreOffice from the command line you need to close all existing instances of Libreoffice. This means closing all GUI sessions of LibreOffice as well as inspecting TaskManager for soffice.exe or a LibreOffice process running the background.
One Item:
PS &("C:\Program Files (x86)\LibreOffice 4\program\soffice.exe") -headless -convert-to txt:Text -outdir C:\Temp C:\Temp\test\sample.doc
This created a file sample.txt in C:\Temp from the document sample.doc
Multiple Items:
foreach ($file in Get-ChildItem C:\Temp\test)
{
&("C:\Program Files (x86)\LibreOffice 4\program\soffice.exe") -headless -convert-to txt:Text -outdir C:\Temp C:\Temp\test\$file | Out-Null
}
This created a .txt file for every file in the folder C:\Temp\test
Again: Use task manager to ensure that a previous version of soffice.exe is not running. This means closing existing GUI versions of LibreOffice.
Explanation:
Here is the documentation regarding Starting LibreOffice Software With Parameters. This will explain the soffice.exe command executed above.
Headless mode starts the LibreOffice software without a GUI. What I refer to in the question as 'command line mode'.
-convert-to is an important parameter in this example. When using -convert-to you need to know what the output_filter_name is (Text in the example above). A reference for those names can be found here. The output_filter_name will be the name of the files in that list that have the suffix .xcu
For example, if I wanted to convert my .doc files to .pdf I would use the parameter -convert-to pdf:writer_pdf_Export (untested)
Here is a reference I used when answering this question.
For some reason .exe processes need to pipe to Out-Null to avoid overlapping one another. Go figure.
The solution above was close, but required some alteration on LibreOffice 4.2 / Linux:
soffice --headless --convert-to txt:Text /path_to/file_to_convert.odt
(I did it with odt, the example I followed used doc: http://ask.libreoffice.org/en/question/14130/how-do-i-install-filters-for-the-soffice-command/)
An additional and important thing to add to #kevinaskevin 's answer is - the workaround is:
From the devs via IRC:
LO's "user installation" (i.e., ~/config/libreoffice) isn't designed to be accessed simultaneously by multiple processes; so when one soffice.bin is already running for a specific user installation, additional soffice.bin just forward their cmd line args to the first one and terminate immediately again (i.e., they shouldn't "fail" in the sense of exiting with a non-zero exit value)
if you want an independent headless LO, you can start it with an own user installation, -env:UserInstallation=<file URL to dir>
I need to know how I could make a batch file that would execute / run a txt file as if it was an exe file. Does any one know what I could do or try. I am using windows 7 ultimate 32 bit. The txt file is an exe just with the .txt extension.
If it is an EXE, why is it named .txt?
Sometimes EXEs are renamed to be able to send them per EMail (some Email-servers are blocking EXEs for security reasons)
Best way is to rename it to .exe
If you really want to stay it as .txt make a copy:
copy file.txt file.exe
file.exe
Note: Don't run any executable if you don't fully trust the source!
One way might be to alter the HKEY_CLASSES_ROOT\txtfile\shell\open\command registry key to change what happens when .txt files are opened.
The default setting is to open with notepad.exe
%SystemRoot%\system32\NOTEPAD.EXE %1
Another way could be to rename the file to.exe, run it, rename it .txt when finished.
There's no need for copying the .txt file to a .exe extension.
This only works if the file is executable
Simply put in batch script:
call yourfilename.txt
or just open CMD and type the same thing, this works only if the .exe file
was renamed to .txt extension, same works as for .run, .dat, .bin, .bmp and
so on, for example:
call chrome.x
or lets try starting CMD with .bmp extension
call cmd.bmp
This will work on all the files that have executable code, other files will not work!
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?
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.
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
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
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.