How can I tell my AppleScript to ignore renamed files? - file

I put together a simple AppleScript that automatically opens new files, that are added to a specific folder. This works great! Problem is, if I rename the new file, then automator runs and re-opens the document. The naming convention is limited by the scanner, but is:
2022-12-21-191532
Year-Month-Date "-"
Random number (timestamp maybe?)
".pdf"
Is there a way to make my script only run on new files and ignore files that are renamed?
The settings are "AppleScript" & "on adding"
on adding folder items to this_folder after receiving added_items
delay 30
try
tell application "Finder"
--get the name of the folder
set the folder_name to the name of this_folder
--go to the desktop
activate
open this_folder
open added_items
reveal the added_items
end tell
end try
end adding folder items to
I tried googling this, but all I keep finding are examples on how to automate renaming files.

Here is an AppleScript solution which you may find useful.
This following AppleScript code will display a dialog allowing you to enter a new file name to rename your currently selected file, in Finder, to the new name. Before it renames the file, it will temporally disable all Folder Actions, then renames the file, then re-enables your Folder Actions. This way, simply renaming your file wont trigger your Folder Actions to run.
tell application "Finder"
if (count of (get selection)) ≠ 1 then
tell current application
activate
display dialog "Please Make Sure Only One File Is Selected" buttons ¬
{"OK"} default button "OK" giving up after 4
end tell
return
else
set nameOfFile to name of item 1 of (get selection)
tell current application
activate
set newName to text returned of ¬
(display dialog "Rename file " & nameOfFile & ¬
" to..." default answer "New File Name" buttons ¬
{"Cancel", "OK"} default button 2 cancel button 1 with icon 1)
end tell
set renameThisFile to item 1 of (selection as alias list)
end if
end tell
tell application "System Events"
if folder actions enabled then set folder actions enabled to false
delay 0.1
set name of renameThisFile to newName
delay 0.1
if not folder actions enabled then set folder actions enabled to true
end tell
What you could do is take the code from above, then in Automator create a new Quick Action, add a Run AppleScript command to the workflow and insert the AppleScript code.
After you name and save your new Automator Quick Action, you can then shoot over to System Preferences/Settings and assign it a keyboard shortcut.
Now anytime you are in Finder, you can rename your currently selected file with your new keyboard shortcut and you will not trigger your Folder Actions.
I have a Folder Action that automatically adds the tag "Aquarium" to any item added to this one specific folder. This following animation demonstrates me first renaming "file 1.txt" to "file.txt" in Finder (the normal way). As you can see, simply remaining that file did trigger the folder action which automatically added the tag to the renamed file. Then, I used my new keyboard shortcut to rename the selected file "file 2.txt" to "xxx" in Finder, without triggering the Folder Action to add the tag to the file after renaming it.

Related

Logic Apps SharePoint Connector - Move file with new file name

We have a integration requirement to move files from one folder to another in SharePoint Online. The new file name in the destination folder needs to be suffixed with the current datetime. For instance, if the source filename is Myfile.csv, it should be moved with the new name Myfile_2021-04-15T15:39:23.csv to the destination folder.
Using the Logic App SharePoint Move file action, I haven't been able to achieve this
If another file is already there is an enum and I'm unable to provide a custom expression for it. Further, with this option files are only renamed if there's a file with the same name already existing in the destination folder. Whereas our requirement is to attach datetime to all files that are being transferred, independent whether the file already exist in the destination folder or not.
How can I best achieve this?
Thanks in advance for any assistance.
Since the "Move file" action doesn't provide a feature for us to specify the new file name, I think the requirement can't be implemented by this action. You can just use other action to do it.
For example, use "Get file content" action to get the file content.
Then use "Create file" action to create the new file in the location which you want.
You can specify a name which you want in the "File name" input box.
By the way, the "Get file content" action doesn't provide an expression of file name for us to use in second step. But I noticed that you have got Full path in your description, so you can substring the Full path to get the original file name. And then use utcNow() method to get the current date and append it to file name.

Getting Maya Custom Hotkeys List

I want to share my Maya hotkeys for custom commands along team. Of course, I can use "hotkeySet" command with -export, -import. But in this case, it override all of them with the file. It means that
If I change "save file" to "Ctrl + Alt + S" (sure, it's so weird). I
don't want to make my team members to use that weird hotkey.
How can I get the list of my custom hotkeys? If I can know that, I can export and import them selectively.
If you want to share your Maya's custom hotkeys along your colleagues, you'll need to copy userHotkeys.mel (or userHotkeys_Maya_Default_Duplicate.mel) and userNamedCommands.mel files from your comp to the destination team's comp. One more file named userRunTimeCommands.mel is typically empty one.
These files are located in the following directories on different OS:
macOS – ~/Library/Preferences/Autodesk/maya/2016.5/prefs/hotkeys
Linux – ~<username>/maya/2016.5-x64/prefs
Windows – \Users\<username>\Documents\maya\2016.5-x64\en_US\prefs
If you open Maya's Script Editor and check Echo all Commands option
on and then save a custom shortcut in Hotkey Editor, you'll notice that Maya saves/updates these three files when you create or edit your hotkey.
For instance, I've created hotkey Alt G for toggling a grid in Viewport.
hotkey -keyShortcut "g" -alt -name ("ToggleGridNameCommand");
This is what I can see in Script Editor:
After that you can share saved userHotkeys.mel and userNamedCommands.mel files along your team. Also you can edit these ASCII files in any Text Editor.

Delete multiple files - Receive only one authentication prompt

I'm trying to create a script to delete multiple files in the same folder without having to authenticate twice. I've tried a bunch of things but I'm super new to AppleScript and I keep striking out. Any assistance is greatly appreciated.
set colorProfiles to (POSIX file "/Library/ColorSync/Profiles")
set coatedToDelete to "Pantone+ Solid Coated.csv"
set uncoatedToDelete to "Pantone+ Solid Uncoated.csv"
try
--Notification window with info
display dialog ("This script will automagically delete your outdated Pantone color books. Please make sure an admin is nearby to authenticate (twice) if prompted.") with icon note
--Deletes both Pantone+ .csv files
tell application "Finder"
delete file (coatedToDelete of folder colorProfiles)
delete file (uncoatedToDelete of folder colorProfiles)
end tell
--Successful deletion notification
display dialog ("The outdated color book deletion was successful!") buttons {"Great!"} with icon note
on error
--Error message notification
display dialog ("This script was unable to delete your legacy Pantone color books.") buttons {"OK"} with icon caution
end try
Use the shell command rm, it can delete multiple files in one line with one authentication. The difference to the Finder is that the files are deleted immediately instead of being moved to the trash folder.
set colorProfiles to "/Library/ColorSync/Profiles/"
set coatedToDelete to colorProfiles & "Pantone+ Solid Coated.csv"
set uncoatedToDelete to colorProfiles & "Pantone+ Solid Uncoated.csv"
try
--Notification window with info
display dialog ("This script will automagically delete your outdated Pantone color books. Please make sure an admin is nearby to authenticate (twice) if prompted.") with icon note
--Deletes both Pantone+ .csv files
do shell script "/bin/rm " & quoted form of coatedToDelete & space & quoted form of uncoatedToDelete with administrator privileges
--Successful deletion notification
display dialog ("The outdated color book deletion was successful!") buttons {"Great!"} with icon note
on error
--Error message notification
display dialog ("This script was unable to delete your legacy Pantone color books.") buttons {"OK"} with icon caution
end try

How does the 'Change Explorer' view work in RTC source control

I have a component which contains outgoing changes :
When I right click this component and compare against the 'initial baseline' I get a list of change sets which comprise this component. This is displayed in the 'Change Explorer' view :
Is this the list of change sets over time that have been delivered to this component or change sets that have been delivered to a baseline, or is it both ?
By right clicking on each change set I see the option to 'accept' the change set. Should this copy the selected changeset into my workspace ?
If you see accept on a changeset, that means it is part of the incoming changes, done and delivered over time on the stream.
If you accept those, and if your component is loaded in your sandbox, then yes, those files will be copied over on your hard drive.
To be clearer, the "Change Explorer" (compared to your classic "Pending Changes" view) is about source control exploration (ie finding, and if needed, accepting old changeset that you need to see back in your repo workspace, and, if the corresponding component is loaded, in your sandbox or hard-drive)
See "Practicing source control archaeology with Rational Team Concert"
Choosing Open in Change Explorer on a change set will show you the all the file versions and directories involved in that change set.
Decorators and clarifying comments are displayed to help your understanding of what had occurred:
File or directory changed:
File or directory added:
File or directory deleted:

How to start the associated program when selecting more than one files?

I have set .jpg file associated to my own program. I want to add the context menu to .jpg files, so I set the entry of HKCR.jpg\shell\open\command to "myProg.exe %1". After associating, there will be an item on the top of the context menu saying "Open image with myprog". This works right when I select a single .jpg file, but when I selected more than one file and click the top item of the context menu, nothing happended. How can I solve the problem?
Thank you very much
Each selected file will be sent to a new instance of your application. Your application should check if a previous version exists, or not. If a previous instance exists, it should sent its parameters to it (e.g. using Windows Messages) and then terminate.
Another approach is to use DDE (Dynamic Data Exchange), an old method used by Shell to send all files to one instance of your program.
You might need double quotes around the "%1".
Read this article for much more detailed information about how all this works.
http://msdn.microsoft.com/en-us/library/bb776883.aspx
Also, this blog entry talks about what you need to do specifically for multi-select command execution: http://blogs.msdn.com/pix/archive/2006/06/30/652889.aspx

Resources