Your best friend for file transfer.

Fetch application logoFetch

AppleScript (2 posts)

This is an archived topic. The information in it is likely to be out-of-date and no longer applicable to current versions of Fetch.
  • Started 9 years ago by JWB
  • Latest reply 9 years ago from Jim Matthews
  • JWB Member

    Greetings!

    I've been using Fetch for a number of years and have only recently gotten into AppleScripting it.

    The example scripts that came with the program are very nice and have helped me a lot by their example.

    I thought I would contribute a script I've found useful. This script creates 7 folders in the directory you're looking at using Fetch; they are named for today and the next six days. If you've already created a few days' worth of folders, the script creates seven more starting the day after the last folder already there. A dialog box gives some control.

    I've done this in AppleScript 1.9.3 for OSX 10.3.4. One "sort" command uses Acme Script Widgets OSAX but I suspect you can get along without using the "sort" command.

    The text of the script follows this message if the bulletin board will support it; if it does you, you can download the file as an OSX .ZIP archive from http://d57-51-120.home.cgocable.net/~jwb/7days.zip

    Regards, John Bast
    Windsor, Ontario

    property Plus1 : 86400
    property theMonths : {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
    global NumberDate, StartDate, NextDays

    OpeningDialog()
    GetSevenDays()

    tell application "Fetch 4.0.3"
    activate
    repeat with i from 1 to 7
    set dirName to item i of NextDays as text
    try
    make new remote directory at beginning with properties {name:dirName}
    on error
    display dialog ¬
    "Directory may already exist!" buttons {"Cancel"} default button 1 with icon 0
    exit repeat
    end try
    end repeat
    end tell

    tell me
    activate
    display dialog "All done!" buttons {"OK"} default button 1 giving up after 5
    end tell

    on GetSevenDays()
    set testDate to current date
    set TextDate to testDate
    DateToNumbers(TextDate)
    set testDate to NumberDate
    set i to 0
    repeat while testDate < StartDate
    set i to i
    set testDate to (current date) Plus1 * i)
    set TextDate to testDate
    DateToNumbers(TextDate)
    set testDate to NumberDate
    end repeat

    set NextDays to {}
    set j to 0
    copy testDate to end of NextDays
    repeat while (count of NextDays) < 7
    set j to j
    set TextDate to (current date) Plus1 * (i ))
    if TextDate as text does not contain "Sunday" then
    DateToNumbers(TextDate)
    copy NumberDate to end of NextDays
    end if
    end repeat
    end GetSevenDays

    (*on OpeningDialog()
    set TextDate to (current date)
    DateToNumbers(TextDate)
    set theInput to display dialog ¬
    "What folder date should I start with?" buttons {"Cancel", "OK"} default button 2 default answer NumberDate with icon 1
    set StartDate to text returned of theInput
    end OpeningDialog*)

    on OpeningDialog()
    set FolderNames to {}
    tell application "Finder"
    set appList to the name of every application process
    end tell
    set Good to "N"
    if appList contains "Fetch 4.0.3" then
    tell application "Fetch 4.0.3"
    if exists transfer window 1 then
    set Good to "Y"
    end if
    end tell
    end if

    if Good = "Y" then
    tell application "Fetch 4.0.3"
    set transferWind to transfer window 1
    repeat with i from 1 to (count transferWind each remote item)
    set curItem to (a reference to remote item i of transferWind)
    set FileName to name of curItem
    copy FileName to end of FolderNames
    end repeat
    end tell

    set DateFolders to {}
    repeat with i from 1 to (count of FolderNames)
    set curName to item i of FolderNames
    set curNums to {}
    repeat with j from 1 to (count of characters of curName)
    set Good to "N"
    if not (((ASCII number of (character j of curName)) > 47) and ((ASCII number of (character j of curName)) < 58)) then
    exit repeat
    else
    set Good to "Y"
    end if
    end repeat
    if Good = "Y" then copy curName to end of DateFolders
    end repeat
    if DateFolders != {} then
    set derDates to Acme sort DateFolders into ascending order
    set SD to last item of derDates
    set SD1 to ((SD as real) ) as integer as text
    if (count of characters of SD1) as text != 4 then
    set StartDate to "0" & SD1 as text
    else
    set StartDate to SD1 as text
    end if
    set theInput to display dialog ¬
    "What folder date should I start with?" buttons {"Cancel", "OK"} default button 2 default answer StartDate with icon 1
    set StartDate to text returned of theInput
    else
    set TextDate to (current date)
    DateToNumbers(TextDate)
    set theInput to display dialog ¬
    "What folder date should I start with?" buttons {"Cancel", "OK"} default button 2 default answer NumberDate with icon 1
    set StartDate to text returned of theInput
    end if
    else
    display dialog "Make sure you have Fetch open, and you're looking in the directory where you want the dated folders to appear." buttons {"Cancel", "OK"} default button 1 with icon 2
    end if
    end OpeningDialog

    on DateToNumbers(TextDate)
    set TextDate to TextDate as text
    set theDate to word 3 of TextDate as integer
    if theDate < 10 then
    set theDate to "0" & theDate as text
    else
    set theDate to theDate as text
    end if
    set theMonth to word 2 of TextDate
    repeat with i from 1 to 12
    if item i of theMonths = theMonth then
    set theMonth to i as integer
    exit repeat
    end if
    end repeat
    if theMonth < 10 then
    set theMonth to "0" & theMonth as text
    else
    set theMonth to theMonth as text
    end if
    set NumberDate to theMonth & theDate
    end DateToNumbers

    Posted 9 years ago #

  • Jim Matthews Administrator

    Thanks for sharing your script!

    Jim Matthews
    Fetch Softworks

    Posted 9 years ago #

Topic closed

This topic has been closed.