<kbd id="9plqc"><label id="9plqc"></label></kbd>

        <th id="9plqc"></th>
        1. <center id="9plqc"><video id="9plqc"></video></center>
          <sub id="9plqc"><form id="9plqc"><pre id="9plqc"></pre></form></sub>
          <nav id="9plqc"><form id="9plqc"><legend id="9plqc"></legend></form></nav>
          修改 AirDrop 文件存放位置 您所在的位置:網(wǎng)站首頁 macbook修改文件名 修改 AirDrop 文件存放位置

          修改 AirDrop 文件存放位置

          2024-01-17 09:47| 來源: 網(wǎng)絡(luò)整理| 查看: 265

          背景

          「滴滴滴」,你的 Mac 收到了你 AirDrop 的文件,并「貼心」地把它存放在了?Downloads?(下載)文件夾下,而你卻并不期望它自動存放在下載文件夾目錄下,至少我不是的。

          下載文件夾結(jié)構(gòu)

          我喜歡給文件來源分類,譬如上圖的樣子,這樣在很容易知道文件來源。

          如何自定義存放路徑?

          按照「慣例」 Mac 上的一些配置都是以 plist?文件來管理的,只要找到對應(yīng)的?plist?文件就可以「魔改」它。然而,讓我失望的是:網(wǎng)上沖浪了一圈,并沒有發(fā)現(xiàn)對應(yīng)的配置文件??。如果你知道請告訴我。

          那么有沒有其他途徑呢?

          Folder Actions什么是 Folder Actions

          Folder Actions is a feature of macOS that lets you associate AppleScript scripts with folders. A Folder Action script is executed when the folder to which it is attached has items added or removed, or when its window is opened, closed, moved, or resized. The script provides a handler that matches the appropriate format for the action, as described in this chapter.

          大概翻譯為:Folder Actions 是 macOS 的一項(xiàng)功能,可讓你將 AppleScript 腳本與文件夾進(jìn)行關(guān)聯(lián)。當(dāng)關(guān)聯(lián)的文件夾有添加或刪除的項(xiàng)目,或者其窗口打開,關(guān)閉,移動或調(diào)整大小時,將執(zhí)行“文件夾作”腳本。詳情可以點(diǎn)擊這里查看官方文檔。

          思路

          按照文檔的說法,只要我寫好一個 AppleScript 腳本并與下載文件夾關(guān)聯(lián),那么當(dāng) Mac 接收到 AirDrop 來的文件時,就自動移動該文件到我期望的文件夾下。看起來似乎可行。

          不過,要想移動 AirDrop 來的文件,就必須知道該文件是通過 AirDrop 方式來的,那么如何識別出下載文件夾下新增的文件是 AirDrop 來的呢?

          ??文件屬性

          macOS 下有「文件屬性」這一概念,如果你經(jīng)常使用命令行,那么你對?ls?指令一定不陌生。在日常?ls -la?時,可能會遇到某些文件的權(quán)限列表后面還會有?@?符號,它就代表該文件有擴(kuò)展屬性。

          ls -la

          抑或是你從互聯(lián)網(wǎng)上下載了某一應(yīng)用,當(dāng)你第一次打開該應(yīng)用時系統(tǒng)會提示「您確定要打開它嗎?”如果您對文件的安全性有疑問,應(yīng)點(diǎn)按“取消”」。這也是利用「文件屬性」這一特性來實(shí)現(xiàn)的。

          那么我只要利用這一特性,來判斷文件是否來源于 AirDrop 即可篩選出所需移動的文件。

          經(jīng)查 AirDrop 對應(yīng)?com.apple.quarantine?屬性的值為 59 。

          quarantine實(shí)現(xiàn)創(chuàng)建 AppleScript 腳本

          首先,確保?/Users/username/Library/Scripts/?路徑下是否有?Folder Action Scripts?文件夾 —— 用來存放所需的腳本。沒有則創(chuàng)建。

          然后在該目錄下(/Users/username/Library/Scripts/Folder Action Scripts)創(chuàng)建 AppleScript 腳本,形如:AirDrop.scpt ,文件名取一個你喜歡的即可。腳本內(nèi)容為:

          property AIRDROP_FOLDER : "Macintosh HD:Users:username:Downloads:AirDrop" # 期望的路徑,用 : 分割 property QUARANTINE_KEY : "59" property GET_QUARANTINE_COMMAND_START : "ls -l -@ '" property GET_QUARANTINE_COMMAND_END : "' | tr '\\n' ' ' | sed 's/.*com\\.apple\\.quarantine\\s*\\(\\d*\\)/ \\1/' | awk '{$1=$1};1'" on adding folder items to this_folder after receiving added_items repeat with i from 1 to length of added_items set current_item to item i of added_items set quarantine_type to getQuarantineType(POSIX path of current_item) if quarantine_type is equal to QUARANTINE_KEY then moveFile(current_item, alias AIRDROP_FOLDER) end if end repeat end adding folder items to on moveFile(move_file, destination_dir) tell application "Finder" move move_file to destination_dir with replacing end tell end moveFile on getQuarantineType(file_path) return do shell script GET_QUARANTINE_COMMAND_START & file_path & GET_QUARANTINE_COMMAND_END end getQuarantineType

          腳本內(nèi)?AIRDROP_FOLDER?需要修改為自己期望的路徑,注意路徑分割符需用?:?而不是常見的?/。

          腳本邏輯為:當(dāng)新增文件的文件屬性?com.apple.quarantine?值為 59 時,就將該文件移動到?AIRDROP_FOLDER?設(shè)置的路徑內(nèi)。

          配置

          右鍵下載文件夾,服務(wù),打開 Folder Actions 設(shè)置。

          Open Folder Actions SetupConfirm Service

          點(diǎn)擊「運(yùn)行服務(wù)」即可看到以下窗口:

          Folder?Actions?Setup

          在左邊的配置窗口里添加下載文件夾,在右邊的配置窗口里添加我們剛剛編寫的?AirDrop.scpt?腳本。

          自此,大功告成。當(dāng)你再 AirDrop 到電腦上文件時,一旦文件接收完畢,系統(tǒng)就會自動將該文件移動到你設(shè)置的目錄里啦。

          如果你遇到什么問題歡迎評論區(qū)交流。

          #EOF



          【本文地址】

          公司簡介

          聯(lián)系我們

          今日新聞

          推薦新聞

          專題文章
            CopyRight 2018-2019 實(shí)驗(yàn)室設(shè)備網(wǎng) 版權(quán)所有
            黄色免费网站在线看,韩国精品在线观看,韩国美女一区二区,99国产热 方山县| 东辽县| 夏津县| 万载县| 西青区| 元谋县| 诸城市| 格尔木市| 崇州市| 宜兰县| 庆元县| 百色市| 楚雄市| 彝良县| 堆龙德庆县| 梨树县| 定兴县| 洛川县| 德庆县| 饶平县| 石首市| 卢湾区| 繁昌县| 行唐县| 双柏县| 江源县| 泸州市| 西乌| 伊春市| 阿合奇县| 广东省| 民丰县| 上犹县| 庆城县| 姜堰市| 江西省| 崇左市| 汉阴县| 达孜县| 平武县| 宁陵县| http://444 http://444 http://444 http://444 http://444 http://444