finder – Automatically Delete Files From Downloads Folder Daily Unless Tagged With “Keep”?

Automatically Delete Files From Downloads Folder Daily Unless Tagged With “Keep”?

The following example AppleScript code can be used in a shell script with an /usr/bin/osascript shebang, or an AppleScript script/application, or a Run AppleScript action in an Automator workflow to delete any file in the targetFolder that does not have a custom “Keep” Tag set in Finder:

-- # targetFolder can be either an HFS path or a POSIX path,
-- # "path:to:target:folder:" or "/path/to/target/folder"
-- # 
-- # Change the value of targetFolder from "/path/to/target/folder"
-- # to the appropriate fully qualified pathname in either form.

set targetFolder to "/path/to/target/folder"


-- # The remaining code should not need to be modified, 
-- # unless the mdfind query needs to be changed.

set targetFolderPOSIXpath to ¬
    the quoted form of ¬
        the POSIX path of targetFolder

set shellCMD to {¬
    "mdfind -onlyin", space, ¬
    targetFolderPOSIXpath, space, ¬
    "'! kMDItemKind == Folder && ! kMDItemUserTags == Keep'"} ¬
    as string

set posixFilesToDelete to ¬
    paragraphs of ¬
    (do shell script shellCMD)

set filesToDelete to {}
repeat with thisFile in posixFilesToDelete
    set thisFile to POSIX file thisFile as alias
    set the end of filesToDelete to thisFile
end repeat

if filesToDelete is not {} then ¬
    tell application "Finder" to ¬
        delete filesToDelete 

Note: Scroll to see remaining code.


Notes:

  • As I do not have the target folder mentioned in the OP, I could not test for any permissions issues that may need addressing in: System Preferences > Security & Privacy > Privacy
  • The example AppleScript code was tested and work for me without issue in macOS Catalina using a temporary folder created within my Home folder while adding files and folders to it and tagging only some files with a custom “Keep” Tag in Finder.
  • As to “Automatically Delete Files” there are a number of different ways to accomplish this depending on how the example AppleScript code is used. If used as an Automator workflow created as a Folder Action using a Run AppleScript action the code can be used as is, replacing the default default code once the targetFolder variable is set.
  • Used as an AppleScript shell script or application it can be scheduled to run at whatever time you’d like, using any of several different methods.

Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

Avoid automatically redirecting to search result in DuckDuckGo

Sometimes DuckDuckGo will automatically redirect me to one of the search results. For example if I search for

https://duckduckgo.com/?q=%5C%40namedef

I will land on the stackexchange site https://tex.stackexchange.com/questions/126273/correct-usage-of-namedef-and-nameuse instead of the a site with the search results.

Can this behaviour be switched off somehow?

P.S. I have already switched off “Instant Answers”

enter image description here

ssh – Cannot enter password automatically in Terminal PuTTY plink command to connect CentOS 7 in Windows

I want to connect CentOS 7 in Windows Terminal, when I use command:

ssh root@192.168.50.160

The arrow keys works well, but ssh command can’t enter password automatically.

So, I use PuTTY plink command like this:

plink -ssh 192.168.50.160 -l root -pw password

But the arrow keys are not working.

How to fix this? Or is there another way to connect to Linux can enter password automatically in Windows Terminal?

How can I automatically add someone’s following to a Twitter List

I want to create a Twitter list that consists of all of a users “following”. Not followers, but the users that user is following. There are roughly 2k accounts I want to add to that list. Because of this, I want to be able to do this automatically.

I have some experience with APIs through Python and would be willing to learn to write a script for this if possible. If it is possible, please recommend some libraries that could be of use.

Thanks!