用于管理 Mac OS X (10.6) 上的下载日期空间的脚本

发布于 2024-10-15 22:02:40 字数 3176 浏览 1 评论 0原文

过去我创建了一个 applescript for datespace 但它不再运行了。

我想创建一个 applescript 来查看文件夹 ~/Documents/pool/~/Downloads 内部。

假设我们是在 2011 年 2 月 7 日。

  1. 检查 ~/Documents/2011/02/07/ 是否存在
  2. 如果不存在则创建 ~/Documents/2011/02/07/ >
  3. ~/Documents/pool/ 内的文件和/或文件夹移动到 ~/Documents/2011/02/07/

额外

  1. ~ 中创建一个文本文件/Documents/2011/ 名称为 index.mdown 并包含以下格式
# Index 2011
## January
[…] 
## February 
* 2011-02-07: Foo.jpeg 
* 2011-02-07: Bar/ 

欢迎提供线索或不完整的解决方案。

上一个脚本

-- Script to automaticaly save documents in a date space.
-- Karl Dubost - http://www.la-grange.net/ - <karl@*******> - 2001 ©
-- Feel free to distribute it and modify it
-- Feel free to send me improvements 
-- ********************************************************
-- Version 1.1 2001-03-30
--      Add control on existence of folders year and month
--      Make it more general based on Startup Disk
-- Version 1.0 2001-03-29
--      Creation of the code
--      Thanks to Bill Briggs
--      http://maccentral.macworld.com/columns/briggs.shtml
-- ********************************************************
on adding folder items to this_folder after receiving added_items
    tell application "Finder"
        set yourDisk to name of startup disk as string
    end tell
    set todaysDate to (current date)
    set {d, m, y} to {day, month, year} of todaysDate
    set monthList to {January, February, March, April, May, June, ¬
        July, August, September, October, November, December}

    repeat with i from 1 to 12
        if m = (item i of monthList) then
            set monthString to text -2 thru -1 of ("0" & i)
            exit repeat
        end if
    end repeat

    set y to y as string
    set dayString to text -2 thru -1 of ("0" & d)
    set dayString to dayString as string
    set datedFolder to yourDisk & ":Documents:" & y & ":" & monthString & ":" & dayString & ":" as string
    set monthFolder to yourDisk & ":Documents:" & y & ":" & monthString & ":" as string
    set yearFolder to yourDisk & ":Documents:" & y & ":" as string
    set rootFolder to yourDisk & ":Documents:" as string

    tell application "Finder"
        if (folder datedFolder exists) then
            repeat with oneFile in added_items
                move oneFile to folder datedFolder
            end repeat
        else if not (folder yearFolder exists) then
            make new folder at folder rootFolder with properties {name:y}
        else if not (folder monthFolder exists) then
            make new folder at folder yearFolder with properties {name:monthString}
        else
            make new folder at folder monthFolder with properties {name:dayString}
            repeat with oneFile in added_items
                move oneFile to folder datedFolder
            end repeat
        end if
    end tell
end adding folder items to

In the past I had created an applescript for datedspace but which is not running anymore.

I would like to create an applescript that would look inside a folder ~/Documents/pool/ or ~/Downloads.

Let's say we are on February 7, 2011.

  1. Check if the ~/Documents/2011/02/07/ exists
  2. If not create ~/Documents/2011/02/07/
  3. Move the files and/or folders inside ~/Documents/pool/ to ~/Documents/2011/02/07/

Bonus

  1. Create a text file in ~/Documents/2011/ with the name index.mdown and containing the following format
# Index 2011
## January
[…] 
## February 
* 2011-02-07: Foo.jpeg 
* 2011-02-07: Bar/ 

Lead or incomplete solutions are welcome.

Previous script

-- Script to automaticaly save documents in a date space.
-- Karl Dubost - http://www.la-grange.net/ - <karl@*******> - 2001 ©
-- Feel free to distribute it and modify it
-- Feel free to send me improvements 
-- ********************************************************
-- Version 1.1 2001-03-30
--      Add control on existence of folders year and month
--      Make it more general based on Startup Disk
-- Version 1.0 2001-03-29
--      Creation of the code
--      Thanks to Bill Briggs
--      http://maccentral.macworld.com/columns/briggs.shtml
-- ********************************************************
on adding folder items to this_folder after receiving added_items
    tell application "Finder"
        set yourDisk to name of startup disk as string
    end tell
    set todaysDate to (current date)
    set {d, m, y} to {day, month, year} of todaysDate
    set monthList to {January, February, March, April, May, June, ¬
        July, August, September, October, November, December}

    repeat with i from 1 to 12
        if m = (item i of monthList) then
            set monthString to text -2 thru -1 of ("0" & i)
            exit repeat
        end if
    end repeat

    set y to y as string
    set dayString to text -2 thru -1 of ("0" & d)
    set dayString to dayString as string
    set datedFolder to yourDisk & ":Documents:" & y & ":" & monthString & ":" & dayString & ":" as string
    set monthFolder to yourDisk & ":Documents:" & y & ":" & monthString & ":" as string
    set yearFolder to yourDisk & ":Documents:" & y & ":" as string
    set rootFolder to yourDisk & ":Documents:" as string

    tell application "Finder"
        if (folder datedFolder exists) then
            repeat with oneFile in added_items
                move oneFile to folder datedFolder
            end repeat
        else if not (folder yearFolder exists) then
            make new folder at folder rootFolder with properties {name:y}
        else if not (folder monthFolder exists) then
            make new folder at folder yearFolder with properties {name:monthString}
        else
            make new folder at folder monthFolder with properties {name:dayString}
            repeat with oneFile in added_items
                move oneFile to folder datedFolder
            end repeat
        end if
    end tell
end adding folder items to

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

追我者格杀勿论 2024-10-22 22:02:40

我希望这足够好:-):
在一些基本命令行应用程序的帮助下,它在 ~/Documents 文件夹中创建子文件夹(mkdir -p:它不会覆盖现有目录!),将文件移动到那里(mv -n:不覆盖同名文件),然后创建包含添加项目名称的每月日志文件,最后创建一个包含所有每月日志文件的 index.mdown 文件,该文件应如下所示:

2011/01/03: testfile9
2011/02/01: testfile10
2011/02/07: testfile11

现在继续将其附加到您的文件夹,试一试! (也许取消注释 baseFolder 并将其更改为 /tmp/test 或其他内容,或者更改为此文件夹的 POSIX 路径,如果您希望它清理其附加的文件夹。)

property dateFormatForFolder : "+%Y/%m/%d"
property dateFormatForMonthlyLog : "+%Y/%m/"
property dateFormatForYearlyLog : "+%Y/"

on adding folder items to thisFolder after receiving addedItems
set baseFolder to POSIX path of (path to documents folder)
set todaysFolder to do shell script "/bin/date '" & dateFormatForFolder & "'"
set monthsFolder to do shell script "/bin/date '" & dateFormatForMonthlyLog & "'"
set yearsFolder to do shell script "/bin/date '" & dateFormatForYearlyLog & "'"
set fullPath to baseFolder & todaysFolder

createFolder(fullPath)

repeat with i from 1 to number of items in addedItems
set oneItemsPath to (quoted form of POSIX path of item i of addedItems)

try
    moveToFolder(fullPath, oneItemsPath)
end try

set fileName to name of (info for item i of addedItems)
set logThis to todaysFolder & ":   " & fileName
do shell script "echo " & logThis & " >> " & baseFolder & monthsFolder & "log.txt"

end repeat

do shell script "find " & baseFolder & yearsFolder & " -type f -name 'log.txt' -print0 | xargs -0 cat > " & baseFolder & yearsFolder & "index.mdown"

end adding folder items to


on createFolder(fullPath)
do shell script "/bin/mkdir -p " & quoted form of fullPath
end createFolder

on moveToFolder(fullPath, oneItemsPath)
do shell script "/bin/mv -n " & oneItemsPath & " " & fullPath
end moveToFolder

I hope this will be good enough :-) :
With the help of some basic command line applications it creates subfolders in your ~/Documents folder (mkdir -p: it will not overwrite existing directories!), moves files there (mv -n: not overwriting files with the same name), then creates monthly logfiles containing the names of addedItems and finally a index.mdown file with all monthly logfiles which should look like this:

2011/01/03: testfile9
2011/02/01: testfile10
2011/02/07: testfile11

Now go ahead and attach it to your folder, give it a try! (maybe uncomment baseFolder and change it to /tmp/test or something, or to POSIX path of thisFolder, if you want it to clean up the folder it´s attached to.)

property dateFormatForFolder : "+%Y/%m/%d"
property dateFormatForMonthlyLog : "+%Y/%m/"
property dateFormatForYearlyLog : "+%Y/"

on adding folder items to thisFolder after receiving addedItems
set baseFolder to POSIX path of (path to documents folder)
set todaysFolder to do shell script "/bin/date '" & dateFormatForFolder & "'"
set monthsFolder to do shell script "/bin/date '" & dateFormatForMonthlyLog & "'"
set yearsFolder to do shell script "/bin/date '" & dateFormatForYearlyLog & "'"
set fullPath to baseFolder & todaysFolder

createFolder(fullPath)

repeat with i from 1 to number of items in addedItems
set oneItemsPath to (quoted form of POSIX path of item i of addedItems)

try
    moveToFolder(fullPath, oneItemsPath)
end try

set fileName to name of (info for item i of addedItems)
set logThis to todaysFolder & ":   " & fileName
do shell script "echo " & logThis & " >> " & baseFolder & monthsFolder & "log.txt"

end repeat

do shell script "find " & baseFolder & yearsFolder & " -type f -name 'log.txt' -print0 | xargs -0 cat > " & baseFolder & yearsFolder & "index.mdown"

end adding folder items to


on createFolder(fullPath)
do shell script "/bin/mkdir -p " & quoted form of fullPath
end createFolder

on moveToFolder(fullPath, oneItemsPath)
do shell script "/bin/mv -n " & oneItemsPath & " " & fullPath
end moveToFolder
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文