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
Related
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.
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.
I have a script that produces a popup that requires the user to click [Ok]. I have another script that can automate this by using SendKeys, however how can this be done when the the script needs to be run when the user is logged off? The script seems to rely on the desktop environment being active.
Check out a tool like nircmd that can send a BM_CLICK message directly to the button instead of relying on UI/keypresses.
Assuming your message box uses a standard OK button and you have nircmd.exe in the same folder as your script (or in the system path), the following statement should click it:
With CreateObject("WScript.Shell")
.Run "nircmd.exe dlg """" ""The Popup Title"" click ok"
End With
If the title of the message box isn't unique, pass the process name as well:
With CreateObject("WScript.Shell")
.Run "nircmd.exe dlg ""someprocess.exe"" ""The Popup Title"" click ok"
End With
Is there a way that I can make a batch program begin when I put my computer to sleep?
I would like to disable a USB port when I put my computer to sleep. Is this possible if so, how would I go a out doing so?
As this has not been marked as closed I am assuming the author has not been able to piece together the answer from the comments. This answer is derived from those comment hints and gives the detail that perhaps the questioner requires....
If you search for information on using the task scheduler to trigger on the sleep event you get to this page at Microsoft, which contains the following:
Input “Task Scheduler” in search box and press Enter
Click “Create task…” on the Task Scheduler---Action
Go to Triggers, create new triggers
On “Begin the task”, select “On an event”
Select Log to “system” , set “Source” to “Kernel-Power” , Event ID
is “42” and click “Ok”
Go to “Actions” and create a new actions
You can select “Start a program”, “Send an e-mail” and “Display a
message” on action as you need.
Save the task scheduler
On conditions tab, check the box “Wake the computer to run this task”. Click OK.
The information about using devcon.exe is on this microsoft page which shows the following command does the trick:
devcon disable *MSLOOP
You can either make a batch-file calling devcon, or have the task scheduler call devcon directly with the appropriate arguments.
Is that enough detail to explain the solution?
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