5
$\begingroup$

I'd like to run wolfram code (probably a .wls script) on a file or set of files by selecting them in the finder and using Right-click > Services.

For example, long ago I made a convenient service with Automator and Python to convert any selected images to jpeg:

enter image description here

An answer here would make for a very useful tutorial!


Update 1 (Response to @xslittlegrass's solution)

I got your solution to run directly in the terminal and also with the play button in the Automator app. But after I saved the workflow in ~/Library/Services/ and tried to use it from right click menu > service > workflow nothing seems to happen... Any ideas?

$\endgroup$

1 Answer 1

6
+50
$\begingroup$

Here is one way to achieve that using the wolframscript and Automator:

  1. Create a automator script with two steps: a) "Get Selected Finder items" and b) "Run Shell Script"

enter image description here

  1. Define the Wolfram code in the file.wls. Here I'm using a simple example of combining two image files.

    #!/usr/bin/env /usr/local/bin/wolframscript files = DeleteDuplicates[$ScriptCommandLine[[2;;-1]]]; dir = FileNameTake[First@files, {1, -2}]; Export[FileNameJoin[{dir,"combined.png"}],ImageCollage[Import/@files]];

  2. Run the code through finder

enter image description here

$\endgroup$
2
  • $\begingroup$ Plz see my update above. $\endgroup$
    – M.R.
    Commented Jul 26, 2021 at 22:54
  • $\begingroup$ @M.R. Did you have the "Get Selected Finder items" step in the automator script? For me, it appears in the right click menu, not the sub-menu of Service. $\endgroup$ Commented Jul 27, 2021 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.