Split file with Automator and 'split' command - macos

I'm currently using the split command to split a large file into many 50MB files. For example:
split -b50m filename.ext filename.ext.
This works really well, but I'd like to use Automator to create an application that I can give to a friend who is less familiar with the command line.
I realise that there are existing applications which can handle this (e.g. Split&Concat), but I want to use this as an opportunity to learn about Automator. This is what I would like to achieve:
Drop file on application icon (e.g. filename.ext)
Split files and name them filename.ext.aa, filename.ext.ab, ...
Create new files in same location as original file
How do I pass the file name to the command line?

When you save the Automator script as an Application the dropped file is passed to the first action automatically.
Select the Run Shell Script pass the input in as an arguments and access it using $#.
You can use the above split command instead. The following Automator takes the input file and moves it to the ~/Desktop/haha folder.

Related

Automator scripts run Java

I need to use Briss, a .jar program, cut the PDF files in order to be display properly on e-ink readers. The basic step is run briss.jar then select open the chose your PDF file. I need automator to do this sequence of actions for me. I open automator, chose new->service->Service receives selected ->PDF->in finder.
Then I drag the briss.jar file into the workflow. and save as BrissPDF
I do see the BrissPDF when I right click a PDF file. But it does not run at all...... I am guessing I didn't pass the PDF file as an input of the briss.jar. Anyone could help?
THanks
You can open briss through bash.
First, add the Path variable. Second, add "Run Shell Script", choose to pass input as arguments, and write java -jar ~/Applications/briss-0.9/briss-0.9.jar "$1", or wherever your briss.jar file is . The $1 part is replaced with the PDF file path, and is passed as an argument to briss.
Here's a automator screenshot.

Is there a way to run a command line "inside" a symlink?

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...

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?
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.

How to create an executable command prompt script

I usually perform actions in the 7zip command line program. I was thinking about creating a small script to do everything automatically, but I have never written any Windows shell script before and therefore don't even know where to begin.
I would like to make an executable script file which, when a user double-clicks on it, will call the 7zip command line and perform some actions.
First of all, is this possible? And if it is, what is the best way to do this?
You can create a batch script to do this.
It's basically command line commands that run one after another so you don't have to keep typing them in :)
Put the commands you would normally use for 7zip in a notepad file and save it with the extension .bat, then run it.
7z blah blah params
7z more params and args
All your commands will be executed automatically when the previous one finishes.
There are other programming languages you could do this in (or even VBScript) but batch would be perfectly suited to this, and you don't need to install anything extra.
Batch files can run a series of command line commands. Simply create a text file and name it with the .bat extension.
There are plenty of resources on the internet which will provide you with help.

Using vssadmin through a batch command or powershell

I need to access a file that is open by another process all the time. The best way would be for me to use Windows Shadow Copy to create another copy of the file and then use the copied file.
Does anyone know how to use vssadmin to create a backup and extract a specific file through a batch command or power shell? I would like to automate the process to run every night.
Jason
Here is a page with examples on how to create snapshots from a command line with vssadmin:
http://blogs.msdn.com/b/adioltean/archive/2004/12/14/301868.aspx

Resources