Monday, April 22, 2019
  • Index
  •  » Code Exchange
  •  » Remove Dead Aliases from Directory and from it's SubDirectories

#1 2019-04-14 04:22:19 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 62

Remove Dead Aliases from Directory and from it's SubDirectories

Many applications and services create a bunch of dead aliases on your computer online. Is recomended before running this script to temporarily turn off the Internet. Although the script works with the Internet on too.

It is better do not choose System folder, or Startup Disk, because 1) the script consumes a lot of time 2) you’ll get annoyed with the system warnings "Cannot be modified ... because it is required by the OS". The best choice is  a Home folder. Therefore, for greater practicality, it is better to just replace code line:
                   set the_folder to choose folder
                                with this:
                   set the_folder to (path to home folder).

By the nature of the problem being solved, the script consumes several minutes for the HOME folder. But you just need to run it once a week, or once a month. This will save your disk from garbage and reduce its fragmentation. Also, now I'm looking for a way to increase the speed of the script. If someone helped supply this script with Swift fragments, I would be grateful. Or, completely rewrite it as Swift. Well, I'll try to do it myself too.

Applescript:



global cleaned_Alias

set cleaned_Alias to 0
set the_folder to choose folder
clean_alias_files_in_folder(the_folder)
cleaned_Alias

on clean_alias_files_in_folder(the_folder)
   tell application "Finder"
       
           --Check each of the alias files in this disk/folder
           set alias_files_list to alias files of the_folder
           repeat with the_alias_file_ref in alias_files_list
               if not (exists original item of the_alias_file_ref) then
                   delete the_alias_file_ref
                   set cleaned_Alias to cleaned_Alias + 1
               end if
           end repeat
           --Clean the alias files in each sub-folder
           set sub_folders_list to folders of the_folder
       
       repeat with the_sub_folder_ref in sub_folders_list
           my clean_alias_files_in_folder(the_sub_folder_ref)
       end repeat
   end tell
end clean_alias_files_in_folder

Last edited by KniazidisR (2019-04-14 06:10:07 am)


macOS Mojave -- version 10.14.4
Safari -- version 12.1

Offline

 
  • Index
  •  » Code Exchange
  •  » Remove Dead Aliases from Directory and from it's SubDirectories

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)