Workflows

This commit is contained in:
Reinhard Pointner 2019-02-21 00:50:50 +07:00
parent 73386f4b8a
commit 5b87038f29
10 changed files with 330 additions and 0 deletions

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AMFolderAction</key>
<string>AMAddingFolderItems</string>
</dict>
</plist>

View File

@ -0,0 +1,193 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AMApplicationBuild</key>
<string>444.39</string>
<key>AMApplicationVersion</key>
<string>2.9</string>
<key>AMDocumentVersion</key>
<string>2</string>
<key>actions</key>
<array>
<dict>
<key>action</key>
<dict>
<key>AMAccepts</key>
<dict>
<key>Container</key>
<string>List</string>
<key>Optional</key>
<true/>
<key>Types</key>
<array>
<string>com.apple.cocoa.string</string>
</array>
</dict>
<key>AMActionVersion</key>
<string>2.0.3</string>
<key>AMApplication</key>
<array>
<string>Automator</string>
</array>
<key>AMParameterProperties</key>
<dict>
<key>COMMAND_STRING</key>
<dict/>
<key>CheckedForUserDefaultShell</key>
<dict/>
<key>inputMethod</key>
<dict/>
<key>shell</key>
<dict/>
<key>source</key>
<dict/>
</dict>
<key>AMProvides</key>
<dict>
<key>Container</key>
<string>List</string>
<key>Types</key>
<array>
<string>com.apple.cocoa.string</string>
</array>
</dict>
<key>ActionBundlePath</key>
<string>/System/Library/Automator/Run Shell Script.action</string>
<key>ActionName</key>
<string>Run Shell Script</string>
<key>ActionParameters</key>
<dict>
<key>COMMAND_STRING</key>
<string>/usr/local/bin/filebot -script fn:amc --output "$HOME/Media" --action duplicate --conflict index -non-strict --log-file "$HOME/Media/.amc.log" --def excludeList=".amc.excludes" unsorted=y music=y artwork=y "$@" -exec open -R {f} +</string>
<key>CheckedForUserDefaultShell</key>
<true/>
<key>inputMethod</key>
<integer>1</integer>
<key>shell</key>
<string>/bin/bash</string>
<key>source</key>
<string></string>
</dict>
<key>BundleIdentifier</key>
<string>com.apple.RunShellScript</string>
<key>CFBundleVersion</key>
<string>2.0.3</string>
<key>CanShowSelectedItemsWhenRun</key>
<false/>
<key>CanShowWhenRun</key>
<true/>
<key>Category</key>
<array>
<string>AMCategoryUtilities</string>
</array>
<key>Class Name</key>
<string>RunShellScriptAction</string>
<key>InputUUID</key>
<string>501F9637-7146-41E8-958D-E1FAB3C6DABC</string>
<key>Keywords</key>
<array>
<string>Shell</string>
<string>Script</string>
<string>Command</string>
<string>Run</string>
<string>Unix</string>
</array>
<key>OutputUUID</key>
<string>BE76312F-1956-431C-B21E-D5528ED97529</string>
<key>UUID</key>
<string>D7458846-B8ED-44A1-9E97-91736B192F85</string>
<key>UnlocalizedApplications</key>
<array>
<string>Automator</string>
</array>
<key>arguments</key>
<dict>
<key>0</key>
<dict>
<key>default value</key>
<integer>0</integer>
<key>name</key>
<string>inputMethod</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>0</string>
</dict>
<key>1</key>
<dict>
<key>default value</key>
<string></string>
<key>name</key>
<string>source</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>1</string>
</dict>
<key>2</key>
<dict>
<key>default value</key>
<false/>
<key>name</key>
<string>CheckedForUserDefaultShell</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>2</string>
</dict>
<key>3</key>
<dict>
<key>default value</key>
<string></string>
<key>name</key>
<string>COMMAND_STRING</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>3</string>
</dict>
<key>4</key>
<dict>
<key>default value</key>
<string>/bin/sh</string>
<key>name</key>
<string>shell</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>4</string>
</dict>
</dict>
<key>isViewVisible</key>
<true/>
<key>location</key>
<string>696.000000:252.000000</string>
<key>nibPath</key>
<string>/System/Library/Automator/Run Shell Script.action/Contents/Resources/Base.lproj/main.nib</string>
</dict>
<key>isViewVisible</key>
<true/>
</dict>
</array>
<key>connectors</key>
<dict/>
<key>workflowMetaData</key>
<dict>
<key>folderActionFolderPath</key>
<string>~/Downloads</string>
<key>workflowTypeIdentifier</key>
<string>com.apple.Automator.folderAction</string>
</dict>
</dict>
</plist>

View File

@ -0,0 +1,64 @@
package net.filebot.platform.mac;
import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.ui.SwingUI.StandardFileAction.Verb.*;
import java.io.File;
import java.io.FileFilter;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import net.filebot.util.FileUtilities.ExtensionFileFilter;
import net.filebot.util.ui.SwingUI.DynamicMenu;
import net.filebot.util.ui.SwingUI.StandardFileAction;
public class WorkflowMenu extends DynamicMenu {
public static final FileFilter WORKFLOW = new ExtensionFileFilter("workflow");
public File templateFolder;
public File targetFolder;
public WorkflowMenu(String label, File templateFolder, File targetFolder) {
super(label);
this.templateFolder = templateFolder;
this.targetFolder = targetFolder;
}
@Override
protected void populate() {
for (File workflow : templateFolder.listFiles(WORKFLOW)) {
if (isInstalled(workflow)) {
add(createUninstallMenu(workflow));
} else {
add(createInstallMenu(workflow));
}
}
}
protected boolean isInstalled(File workflow) {
return new File(targetFolder, workflow.getName()).exists();
}
protected JMenuItem createInstallMenu(File workflow) {
JMenu menu = new JMenu(getNameWithoutExtension(workflow.getName()));
menu.add(new StandardFileAction("Install", workflow, OPEN));
menu.add(new StandardFileAction("Reveal", workflow, REVEAL));
return menu;
}
protected JMenuItem createUninstallMenu(File workflow) {
JMenu menu = new JMenu(getNameWithoutExtension(workflow.getName()));
menu.add(new StandardFileAction("Uninstall", workflow, TRASH));
menu.add(new StandardFileAction("Open", workflow, OPEN));
menu.add(new StandardFileAction("Reveal", workflow, REVEAL));
return menu;
}
}

View File

@ -26,6 +26,7 @@ import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.util.ArrayList;
@ -44,6 +45,7 @@ import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JMenu;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
@ -52,6 +54,8 @@ import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.Timer;
import javax.swing.UIManager;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import javax.swing.event.MouseInputListener;
import javax.swing.plaf.basic.BasicTableUI;
import javax.swing.text.JTextComponent;
@ -410,6 +414,41 @@ public final class SwingUI {
}
}
public static class StandardFileAction extends AbstractAction {
public enum Verb {
OPEN, REVEAL, TRASH;
}
private File file;
private Verb verb;
public StandardFileAction(String label, File file, Verb verb) {
super(label);
this.file = file;
this.verb = verb;
}
@Override
public void actionPerformed(ActionEvent evt) {
try {
switch (verb) {
case OPEN:
Desktop.getDesktop().open(file);
break;
case REVEAL:
Desktop.getDesktop().browseFileDirectory(file);
break;
case TRASH:
Desktop.getDesktop().moveToTrash(file);
break;
}
} catch (Exception e) {
log.log(Level.SEVERE, e, cause(verb, e));
}
}
}
public static <T> T onSecondaryLoop(BackgroundSupplier<T> supplier) throws ExecutionException, InterruptedException {
// run spawn new EDT and block current EDT
SecondaryLoop secondaryLoop = Toolkit.getDefaultToolkit().getSystemEventQueue().createSecondaryLoop();
@ -506,6 +545,32 @@ public final class SwingUI {
}
}
public static abstract class DynamicMenu extends JMenu implements MenuListener {
public DynamicMenu(String name) {
super(name);
addMenuListener(this);
}
protected abstract void populate();
@Override
public void menuSelected(MenuEvent e) {
removeAll();
populate();
}
@Override
public void menuDeselected(MenuEvent e) {
}
@Override
public void menuCanceled(MenuEvent e) {
}
}
/**
* When trying to drag a row of a multi-select JTable, it will start selecting rows instead of initiating a drag. This TableUI will give the JTable proper dnd behaviour.
*/