安全清倒废纸篓(AppleScript)

  1. on run {input, parameters}
  2. set title to "安全清倒废纸篓"
  3. set trashIsEmptyMessage to "废纸篓是空的,不需要清空。"
  4. set willDeleteMessage to "请选择清空方式?"
  5. set secureDeleteAction to "安全清倒废纸篓"
  6. set secureDeleteActionTerminal to "安全清倒废纸篓(详细)"
  7. set cancelAction to "取消"
  8. set okAction to "好"
  9. set errorMessage to "发生错误:"
  10. set finishMessage to "已经安全清倒废纸篓。"
  11. set srmCommand to "sudo srm -rfsz /Volumes/*/.Trashes ~/.Trash"
  12. set srmVerboseCommand to "sudo srm -rfvsz /Volumes/*/.Trashes ~/.Trash"
  13.  
  14. tell application "Finder"
  15. set trashCount to count of items in the trash
  16. if trashCount = 0 then
  17. beep
  18. activate
  19. display dialog trashIsEmptyMessage buttons {okAction} default button okAction with title title
  20. return input
  21. end if
  22. try
  23. beep
  24. activate
  25. set dialog to display dialog willDeleteMessage buttons {secureDeleteActionTerminal, secureDeleteAction, cancelAction} default button cancelAction with title title
  26. on error
  27. return input
  28. end try
  29. set interface to button returned of dialog
  30. end tell
  31.  
  32. if interface is cancelAction then
  33. return input
  34. end if
  35.  
  36. if interface is secureDeleteAction then
  37. tell application "Finder"
  38. try
  39. do shell script srmCommand with administrator privileges
  40. activate
  41. display dialog finishMessage buttons {okAction} with title title
  42. on error errmsg
  43. beep
  44. activate
  45. display dialog errorMessage & errmsg buttons {okAction} with title title
  46. end try
  47. end tell
  48. else if interface is secureDeleteActionTerminal then
  49. tell application "Terminal"
  50. launch
  51. delay 0.2
  52. activate
  53. do script srmVerboseCommand
  54. end tell
  55. --else if interface is deleteAction then
  56. -- tell application "Finder"
  57. -- empty the trash
  58. -- end tell
  59. end if
  60.  
  61. return input
  62. end run

Finder - 服务 -  安全清倒废纸篓

强行删除(AppleScript)

  1. on run {input, parameters}
  2. set title to "强行删除"
  3. set willDeleteMessage to "此操作将不经过废纸篓*直接删除*选中的文件:"
  4. set fileCountUnitMessage to "个"
  5. set deleteAction to "删除"
  6. set secureDeleteAction to "安全删除"
  7. set cancelAction to "取消"
  8. set okAction to "好"
  9. set finishedMessage to "操作完成"
  10. set errorMessage to "删除期间发生了错误:"
  11. set fileCountZeroMessage to "未选择任何文件或文件夹。"
  12. set deleteCommand to "sudo rm -rf"
  13. set secureDeleteCommand to "sudo srm -rfsz"
  14.  
  15. set fileCount to the count of input
  16. if fileCount = 0 then
  17. beep
  18. activate
  19. display dialog fileCountZeroMessage buttons {okAction} default button okAction with title title
  20. return input
  21. end if
  22.  
  23. set theFiles to ""
  24. set theFilesMsg to ""
  25. repeat with theFile in input
  26. set p to quoted form of (POSIX path of theFile)
  27. set theFiles to theFiles & " " & p
  28. set theFilesMsg to theFilesMsg & "
  29. " & p
  30. end repeat
  31.  
  32. tell application "Finder"
  33. try
  34. beep
  35. activate
  36. set msg to willDeleteMessage & (fileCount as string) & fileCountUnitMessage & theFilesMsg
  37. set dialog to display dialog msg buttons {secureDeleteAction, deleteAction, cancelAction} default button cancelAction with title title
  38. on error
  39. return input
  40. end try
  41. set interface to button returned of dialog
  42. end tell
  43.  
  44. if interface is cancelAction then
  45. return input
  46. end if
  47.  
  48. if interface is deleteAction then
  49. try
  50. do shell script deleteCommand & theFiles with administrator privileges
  51. activate
  52. tell application "Finder" to display dialog finishedMessage buttons {okAction} with title title
  53. on error errmsg
  54. beep
  55. activate
  56. tell application "Finder" to display dialog errorMessage & errmsg buttons {okAction} with title title
  57. end try
  58. else if interface is secureDeleteAction then
  59. try
  60. do shell script secureDeleteCommand & theFiles with administrator privileges
  61. activate
  62. tell application "Finder" to display dialog finishedMessage buttons {okAction} with title title
  63. on error errmsg
  64. beep
  65. activate
  66. tell application "Finder" to display dialog errorMessage & errmsg buttons {okAction} with title title
  67. end try
  68. end if
  69.  
  70. return input
  71. end run

在Finder中选择要删除的文件,右键 - 服务 - 强行删除

显示隐藏文件(Run Shell Script)

  1. STATUS=`defaults read com.apple.finder AppleShowAllFiles`
  2. if [ $STATUS == YES ];
  3. then
  4. defaults write com.apple.finder AppleShowAllFiles NO
  5. else
  6. defaults write com.apple.finder AppleShowAllFiles YES
  7. fi
  8. killall Finder

Finder - 服务 - 显示隐藏文件

打包下载地址:

http://pan.baidu.com/s/1eQsG2PW

mac实用脚本的更多相关文章

  1. QL Server 实用脚本

    use MyFirstDB; -- 主要内容 -- SQL Server 实用脚本 -- 1.case语句 -- 2.子查询 -- 3.连接查询 -- 4.脚本变量与流程控制(选择与循环等) -- 5 ...

  2. Mac实用技巧之:访达/Finder

    更多Mac实用技巧系列文章请访问我的博客:Mac实用技巧系列文章 Finder就相当于windows XP系统的『我的电脑』或win7/win10系统里的『计算机』(打开后叫资源管理器),find是查 ...

  3. 8 个 Python 实用脚本,赶紧收藏备用!

    脚本写的好,下班下得早!程序员的日常工作除了编写程序代码,还不可避免地需要处理相关的测试和验证工作. 例如,访问某个网站一直不通,需要确定此地址是否可访问,服务器返回什么,进而确定问题在于什么.完成这 ...

  4. Python 实用脚本

    Python 实用脚本 脚本写的好,下班下得早!程序员的日常工作除了编写程序代码,还不可避免地需要处理相关的测试和验证工作. 例如,访问某个网站一直不通,需要确定此地址是否可访问,服务器返回什么,进而 ...

  5. 精确报告Linux内存使用情况实用脚本:ps_mem

    精确报告Linux内存使用情况实用脚本:ps_mem 2019-09-06 12:45 ps_mem内存工具 ps_mem 是一个可以帮助我们精确获取 Linux 中各个程序核心内存使用情况的简单 p ...

  6. Unity3D研究院之在MAC上脚本XlsxWriter写入Excel .xlsx格式

    原地址:http://www.xuanyusong.com/archives/3011 以前找了很久可以跨平台支持读写Excel的工具,我也试了很多种DLL.可在Windows上各个完美支持,可是在M ...

  7. macOS 自动修改mac地址脚本

    介于 某公众号提供了通过修改mac地址来链接BUPT_mobile 的推送,上网上查了一下咋写脚本,实现一键修改mac地址的功能 网上有自动修改mac地址的程序,但是很坑爹的要收费,所以不如自力更生写 ...

  8. Mac实用技巧

    1. 程序员Mac新装机必备 Mac很玄这个大家都承认,但是鄙人觉得程序员用Mac才能真正发挥它的功效.下面就说说我的Mac使用: 基本编程软件:xcode,这个东西不仅仅是对mac的界面程序开发有用 ...

  9. 8 个 Python 实用脚本,【速】收藏备用!

    脚本写的好,下班下得早!程序员的日常工作除了编写程序代码,还不可避免地需要处理相关的测试和验证工作. 例如,访问某个网站一直不通,需要确定此地址是否可访问,服务器返回什么,进而确定问题在于什么.完成这 ...

随机推荐

  1. 2015-03-06——ajax基础

    IE6  必须使用Microsoft.XMLHTTP ActiveX组件来实例化一个对象 IE7已实现了XMLHttpRequest对象 var request = new ActiveXObject ...

  2. source $0 & bash $0

    bash file.sh这种形式启动时,$0才被设置成文件名. source是bash的内建命令,把文件读取到当前bash中执行,相当于在当前bash手动输入命令,所以$0是bash. 示例代码如下: ...

  3. C#使用Lock访问共享数据的问题

    lock 语句(C# 参考) lock 关键字将语句块标记为临界区,方法是获取给定对象的互斥锁,执行语句,然后释放该锁.此语句的形式如下: 复制 Object thisLock = new Objec ...

  4. python常用模块-1

    一.认识模块 1.什么是模块:一个模块就是一个包含了python定义和声明的文件,文件名就是加上.py的后缀,但其实import加载的模块分为四个通用类别 : 1.使用python编写的代码(.py文 ...

  5. Android:日常学习笔记(2)——分析第一个Android应用程序

    Android:日常学习笔记(2)——分析第一个Android应用程序 Android项目结构 整体目录结构分析 说明: 除了APP目录外,其他目录都是自动生成的.APP目录的下的内容才是我们的工作重 ...

  6. sorted 、 filter 、 map

    sorted   排序函数 内置函数中提供了一个通用的排序方案 ,返回一个新的列表,不会改变原数据 语法: sorted(iterable, key, reverse) key: 排序方案, sort ...

  7. C++中引用编译过的C代码为什么要用“extern c”

    函数经过编译系统的翻译成汇编,函数名对应着汇编标号.  因为C编译函数名与得到的汇编代号基本一样,如:fun()=>_fun, main=>_main  但是C++中函数名与得到的汇编代号 ...

  8. C# partial 关键字

    C# partial关键字详解 partial关键字允许把类.结构或接口放在多个文件中.一般情况下,一个类存储在单个文件中.但有时,多个开发人员需要访问同一个类,或者某种类型的代码生成器生成了一个类的 ...

  9. 使用CoreData存储数据

    - (void)viewDidLoad { [super viewDidLoad]; //获取模型文件的路径 NSString *path=[[NSBundle mainBundle]pathForR ...

  10. Spring_HelloWord

    环境:IntelliJ 14 : jdk1.8   Spring操作步骤 1.新建项目---Spring Batch 2.IntelliJ会自动加载jar包 3.现在就可以在src目录下写Java类文 ...