Loading ...
Sorry, an error occurred while loading the content.

A classic Finder scripting question

Expand Messages
  • John Kaufmann
    This *should* a simple question - how to delete, or move to another location, all files or items in a specified a folder - yet the answer eludes me. For
    Message 1 of 4 , Dec 5, 2005
    • 0 Attachment
      This *should* a simple question - how to delete, or move to another
      location, all files or items in a specified a folder - yet the answer
      eludes me. For example, I thought it should be possible to say:

      set tempfolder to "HD:F3"
      tell application "Finder"
      move every item of folder ("HD:F1:F2") to folder tempfolder
      end tell

      But nothing happened. So I tried being more explicit about the destination:

      tell application "Finder"
      move every item of folder ("HD:F1:F2") to folder "HD:F3"
      end tell

      Again nothing happened. So I tried first converting the folder to a window:

      tell application "Finder"
      open folder ("HD:F1:F2")
      move every item of front window to folder "HD:F3"
      end tell

      Finally something happened: Folder "HD:F1:F2" was opened as the
      front Finder window, labelled "F2". But that's all that happened;
      nothing was moved. So [with Script Editor such a pitiful debugging
      environment] I tried using a count statement for debugging:

      tell application "Finder"
      open folder ("HD:F1:F2")
      -- move every item of front window to folder "HD:F3"
      count every item of front window
      end tell

      Here there may finally be a clue: Although the opened window showed
      many files, the result of the count (in Script Editor's "the result"
      window) was "0". But why?

      Obviously I must be violating AppleScript syntax in some basic way,
      but how can it get any more basic than this example? [It's enough to
      make a body wish BATch or Rexx or some other less "friendly"
      scripting language were available under MacOS.] Can someone help me
      see what's wrong here?
      --
      John K
    • John Rethorst
      ... This works fine OMM with OS 10.4.3: set folder1 to (path to desktop as string) & folder 1 set folder2 to (path to desktop as string) & folder 2 tell
      Message 2 of 4 , Dec 5, 2005
      • 0 Attachment
        --- In wordperfectmac@yahoogroups.com, John Kaufmann <kaufmann@n...> wrote:
        >
        > This *should* a simple question - how to delete, or move to another
        > location, all files or items in a specified a folder - yet the answer
        > eludes me. For example, I thought it should be possible to say:
        >
        > set tempfolder to "HD:F3"
        > tell application "Finder"
        > move every item of folder ("HD:F1:F2") to folder tempfolder
        > end tell
        >
        > But nothing happened.

        This works fine OMM with OS 10.4.3:

        set folder1 to (path to desktop as string) & "folder 1"
        set folder2 to (path to desktop as string) & "folder 2"
        tell application "Finder" to move every item of folder folder1 to folder folder2

        I think this syntax did not change from Classic to X.

        >[It's enough to
        >make a body wish BATch or Rexx or some other less "friendly"
        >scripting language were available under MacOS.]

        Or at least a better editor. Try the free "Smile" at:

        http://www.tucows.com/preview/207118

        I found the interface daunting at first, but it's very capable.

        John R.
      • John Kaufmann
        ... Hmm... a good test, in that it quickly exposes a difference between OS 8.6, with AS 1.3.7 (where it works) and OS 7.6.1, with AS 1.1 (where it does not
        Message 3 of 4 , Dec 5, 2005
        • 0 Attachment
          At 051205 23:06 +0000, John Rethorst wrote:

          >This works fine OMM with OS 10.4.3:
          >
          >set folder1 to (path to desktop as string) & "folder 1"
          >set folder2 to (path to desktop as string) & "folder 2"
          >tell application "Finder" to move every item of folder folder1 to
          >folder folder2

          Hmm... a good test, in that it quickly exposes a difference between

          OS 8.6, with AS 1.3.7 (where it works)
          and
          OS 7.6.1, with AS 1.1 (where it does not work)

          (Both use AppleScriptLib 1.2.2.) Unfortunately, both are target
          environments for this script, and it was while I was trying to fix a
          problem in a classroom running 7.6.1 that I ran into the problem
          which prompted this thread. Also unfortunately, 7.6.1 will not run
          AppleScript 1.3.7, so I may be stuck on this problem.

          >>[It's enough to make a body wish BATch or Rexx or some other less "friendly"
          >>scripting language were available under MacOS.]
          >
          >Or at least a better editor. Try the free "Smile" at:
          >
          >http://www.tucows.com/preview/207118
          >
          >I found the interface daunting at first, but it's very capable.

          It does look interesting in OS 8.6, but I found that I can't run it
          in the other environment 7.6.1, where I'm having trouble to trace
          (and work around) the problem that began this thread. Again, I may
          be stuck. But I want to thank you for - once again - a quick and
          informative reply.
          --
          John K
        • John Rethorst
          ... OS 7.6.1 uses the Finder Scripting Extension. Is it present on your machine and active via Extensions Manager? If so, it may be corrupted; try a new copy
          Message 4 of 4 , Dec 6, 2005
          • 0 Attachment
            --- In wordperfectmac@yahoogroups.com, John Kaufmann <kaufmann@n...> wrote:

            > Hmm... a good test, in that it quickly exposes a difference between
            > OS 8.6, with AS 1.3.7 (where it works) and
            > OS 7.6.1, with AS 1.1 (where it does not work)
            >
            > (Both use AppleScriptLib 1.2.2.)

            OS 7.6.1 uses the Finder Scripting Extension. Is it present on your
            machine and active via Extensions Manager? If so, it may be corrupted;
            try a new copy from Apple. I just ran this script on a 7.6.1 machine,
            running it from Script Editor and as an applet; worked fine.
          Your message has been successfully submitted and would be delivered to recipients shortly.