I'm trying to set up a single Streamdeck button that triggers one of two different commands, based on which application is currently active in the foreground (even if both applications are currently open).
What the command does, is centre the selected layers in either Adobe Photoshop or Adobe Illustrator.
I'm getting an error on line 1 "error invoking app.activate, could not find running app with bundle id: ' '
// Center in Illustrator
if (sf.ui.app('com.adobe.Illustrator').isActive) {
sf.ui.app('com.adobe.Illustrator').menuClick({
menuPath: ["Object","Align","Horizontal Align Center"],
});
sf.ui.app('com.adobe.Illustrator').menuClick({
menuPath: ["Object","Align","Vertical Align Center"],
});
// Center in Photoshop
} else {
sf.ui.app('com.adobe.Photoshop').menuClick({
menuPath: ["Object","Select","All"],
});
sf.ui.app('com.adobe.Photoshop').menuClick({
menuPath: ["Layer","Align Layers to Selection","Vertical Centers"],
});
sf.ui.app('com.adobe.Photoshop').menuClick({
menuPath: ["Layer","Align Layers to Selection","Horizontal Centers"],
});
}
- Dustin Harris @Dustin_Harris
Try changing the first line to:
if (sf.ui.frontmostApp.activeBundleID === "com.adobe.Illustrator") {
Maybe that will do the trick?
- AAndrew Sherman @Andrew_Sherman8
Thank for your reply Dustin, much appreciated. That helped a lot. After some further tweaks, it's working properly. For anyone interested, the capitilisation in the app id is important (com.adobe.illustrator and com.adobe.Photoshop are correct in this case). For some reason the Photoshop section needed a wait as well.
Here's the script:
// Center in Illustrator if (sf.ui.frontmostApp.activeBundleID === "com.adobe.illustrator") { sf.ui.app('com.adobe.illustrator').menuClick({ menuPath: ["Object","Align","Horizontal Align Center"], }); sf.ui.app('com.adobe.illustrator').menuClick({ menuPath: ["Object","Align","Vertical Align Center"], }); // Center in Photoshop } else { sf.ui.app('com.adobe.Photoshop').menuClick({ menuPath: ["Select","All"], }); sf.wait({ intervalMs: 1000, }); sf.ui.app('com.adobe.Photoshop').menuClick({ menuPath: ["Layer","Align Layers to Selection","Vertical Centers"], }); sf.ui.app('com.adobe.Photoshop').menuClick({ menuPath: ["Layer","Align Layers to Selection","Horizontal Centers"], }); sf.ui.app('com.adobe.Photoshop').menuClick({ menuPath: ["Select","Deselect"], }); }
Dustin Harris @Dustin_Harris
Just for my own practice benefit I refactored this script, adding an
else if
for the photoshop condition, and anelse
so that if you hit the button and you're in neither photoshop or illustrator, it won't throw an error (nothing will happen). Use it if you'd like :)const illustratorID = "com.adobe.illustrator"; const photoshopID = "com.adobe.Photoshop"; // Center in Illustrator if (sf.ui.frontmostApp.activeBundleID === illustratorID) { const illustrator = sf.ui.app(illustratorID); illustrator.menuClick({ menuPath: ["Object", "Align", "Horizontal Align Center"], }); illustrator.menuClick({ menuPath: ["Object", "Align", "Vertical Align Center"], }); // Center in Photoshop } else if (sf.ui.frontmostApp.activeBundleID === photoshopID) { const photoshop = sf.ui.app(photoshopID); photoshop.menuClick({ menuPath: ["Select", "All"], }); sf.wait({ intervalMs: 1000, }); photoshop.menuClick({ menuPath: ["Layer", "Align Layers to Selection", "Vertical Centers"], }); photoshop.menuClick({ menuPath: ["Layer", "Align Layers to Selection", "Horizontal Centers"], }); photoshop.menuClick({ menuPath: ["Select", "Deselect"], }); } else { //do nothing }
- AAndrew Sherman @Andrew_Sherman8
Good idea Dustin, that's even better. Also nice to keep it tidy with defining the constants.
I'm thinking of re-looking at this at some point to give it an option where you use a modifier key (eg press command and then Streamdeck key), which would then just align it horizontally instead of both.
Dustin Harris @Dustin_Harris
Ooohhh... modifier key + streamdeck button isn't something I've tried yet!
Chris Shaw @Chris_Shaw2021-02-15 18:18:59.517Z
modified SD macros are great.
saves a lot of space and redundant keys
- In reply toAndrew_Sherman8⬆:
Raphael Sepulveda @raphaelsepulveda2021-02-15 19:53:09.234Z
cc: @Dustin_Harris
@JesperA wrote an excellent post on how to do this! How to use keyboard modifier keys with Stream Deck and other devices to create multifunctional buttons and "layers".