Is it possible to identify which file is opened in Photoshop and grab its Finder location?
Context: Photoshop doesn't allow Undo after a file is closed, which can sometimes be a problem when I flatten all layers for a specific reason and by accident Save and Close the image (I won't be able to edit the layers anymore).
So my goal was to have KM find the file in Finder when I hit the Save shortcut (so it won't save it right away), it would create a copy of that file to a specific location (backups folder) and only then it would save it. So even if I accidentally flatten layers, save, close, the original file will always be copied to my backups folder.
When I right click the tab of the open image, I can see the Reveal in Finder, so I would assume that this would be done via AS?
If this can be done via AS, it would have to know which image is the front image, because it's possible to have more than 1 image open, just different tabs
I tried that, but for some weird reason (and this is the first time I'm experiencing this) once I add the token, the "beach ball" shows up, then goes away for like 2 seconds, then back, in a loop. Any idea what could cause this?
It only goes away when I delete the token, action, or macro (when I can do it in those 2 second window)
Yes I was going to give it a name, always do, but I started with adding the token first (I have a favorite action and by default it's already set to Local__ so I can then just type the name) and then I couldn't even type anything without it taking forever. For example I tried adding "window" (so Local__window) but it would type "w", then beach ball for like 5 seconds, then "i", beach ball for 5 seconds, etc...
Is it something I could test?
By the way, that token worked like a charm (when I was able to wait until it added the variable name). Thanks
One thing I noticed is that once I select another macro, it goes away.
I found this topic that uses AppleScript instead (in case I can't solve the issue with the token). Would this be an option if I then save the result to a KM variable?
When you use a KM token, KM tries to evaluate it whether you're in the KM Editor or just running your macro. In your case you are in the editor in a macro that's got that token in it and therefore KM is trying to get the path of the document in the frontmost app - which is KM. I don't actually know if KM ever has a "document" so I was wondering if KM is struggling to find the document path resulting in the beach ball.
This may be a complete red herring and that's why I referred the discussion over to @peternlewis
(I can't do any testing myself as I'm away from my office right now.)
Thanks for clarifying. It makes sense what you said, even though it makes it impossible to work if that's the case.
I was thinking of a workaround (besides the AS version), but not sure if this is possible?
Could I set 2 variables and then "merge" them to create the token? Something like this, but when I run this, it shows me the actual token, not the path
I ended up going with the AS solution, with the help of someone at the MacScripter forum. I would still like to understand why I have this issue, but you for example, don't.
So the final script is
tell application "Adobe Photoshop 2020"
set thefile to (file path of current document) --> get the file path (an alias)
set thefile to POSIX path of thefile
set kmInst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine" to setvariable "Local__file" instance kmInst to thefile
And thanks for sharing that token, anyway. Maybe I will be able to use it in the future when this issue isn't there on my computer.
The issue is not with the token not working. It does, with Photoshop.
The issue now is that when a variable is set to %FrontDocumentPath%, KM lags like crazy to a point where it's impossible to work. Just to change the name of the variable by adding the word "window" it takes like 1 minute or more, because it shows the beach ball for like 5 seconds or more, then stops for 2 seconds, types the letter "w", then beach ball for 5 seconds or more, types the letter "i", etc, etc, etc.
To being able to use it, I had to remove the last % for KM to see it as normal text, not a token, and only when I was 100% sure that the macro was done, I added the last % again and quickly clicked another macro to avoid the beach ball again.
That was the issue. I updated to 11.0.2 and it's working now. No lag and I can see the text when KM is the front application (Not available in the editor).
1 - Is there a way to make KM check for updates regularly, other than creating a macro to click the menu to check updates? I don't think I got the notification that a new version was available. It would be good to have that setting in the Settings panel.
2 - I found this topic where you mention that holding shift will show the token, which is useful and I didn't know about it. But I think the search menu could have a few improvements:
Ability for us to search for the token itself, meaning that the list would be sorted alphabetically with the tokens. Right now when I open the search > ALL, the titles are sorted, but when I hit Shift, the tokens are not (of course), so it makes it hard to find by token. For example right now if I know that a particular token starts with %Front but I don't remember the rest, it's really hard (or impossible) to find it, because typing %Front in the search field, shows no results. For the %FrontDocumentPath% the title is not next to the list with the other "Front" tokens
For example the same type of token is described as:
Whereas the front document path is:
So we would either have The path of the front application The path of the front window's document
or Front Application Path Front Document Path
At the same time, when I go to each category, the titles are not sorted, but the tokens are, which is confusing because it's the opposite of the All category
Ability to search for the token by typing % in the search field and it would automatically switch to the token list (sorted alphabetically), similar to when we hit Shift. Right now, nothing is listed:
Another suggestion would be a "token auto complete". For example if I'm creating a new variable and I type a certain combination of characters, for example %% (we could change this to whatever we want) it would trigger an auto completion window. So if I type %%front it would show me a list of tokens that have "front" in it (in any position), but in token form, not title. This would make the process so much faster.
Anyway, thanks for suggesting the updated. The token is working now.
Very strange … @peternlewis may have to chime in on why you don't see notifications. I don't think it's related to your Notifications settings for Keyboard Maestro, though. But I do know I see notifications when there's an update available.