The posted script is a folder action one.
It must be attached to a folder using the application “your HD:System:Library:CoreServices:Applications:Folder Actions Setup.app:” delivered by Apple.
For my tests I attached the script to a folder named “For ASC forums” available on the desktop. This folder contained a subfolder named “storageFolder”
Once it’s done, if you drop a file onto the folder the script will move it into the subfolder “storageFolder” until the physical size of this subfolder reach 1024 * 1024 bytes.
My understanding is that you didn’t attach the script to the folder and tried to run it from the Editor which logically will claims that the variable this_folder is not defined.
As you spoke about “folder action script” in your original message I assumed that you were aware of what this kind of item is.
Clearly I was wrong.
Looking at AppleScript User Guide would be a good idea.
Here is a part of it :[format]Folder Actions Reference
Folder Actions is a feature of OS X that lets you associate AppleScript scripts with folders. A Folder Action script is executed when the folder to which it is attached is opened or closed, moved or resized, or has items added or removed. The script provides a handler that matches the appropriate format for the action, as described in this chapter.
Folder Actions make it easy to create hot folders that respond to external actions to trigger a workflow. For example, you can use a Folder Action script to initiate automated processing of any photo dropped in a targeted folder. A well written Folder Action script leaves the hot folder empty. This avoids repeated application of the action to the same files, and allows Folder Actions to perform more efficiently.
You can Control-click a folder to access some Folder Action features with the contextual menu in the Finder. Or you can use the Folder Actions Setup application, located in /Applications/AppleScript. This application lets you perform tasks such as the following:
Enable or disable Folder Actions.
View the folders that currently have associated scripts
View and edit the script associated with a folder.
Add folders to or remove folders from the list of folders. Associate one or more scripts with a folder.
Enable or disable all scripts associated with a folder.
Enable or disable individual scripts associated with a folder. Remove scripts associated with a folder.
Folder Actions Setup looks for scripts located in /Library/Scripts/Folder Action Scripts and ~/Library/Scripts/Folder Action Scripts. You can use the sample scripts located in /Library/Scripts/Folder Action Scripts or any scripts you have added to these locations, or you can navigate to other scripts.
A Folder Action script provides a handler (see “Handler Reference” (page 275)) that is invoked when the specified action takes place. When working with Folder Action handlers, keep in mind that:
You do not invoke Folder Actions directly. Instead, when a triggering action takes place on a folder, the associated handler is invoked automatically.
â—
â—
â—
Folder Actions Reference
When a Folder Action handler is invoked, none of the parameters is optional. A Folder Action handler does not return a value.
Here’s how you can use a Folder Action script to perform a specific action whenever an image file is dropped on a specific image folder:
- Create a script with Script Editor or another script application.
- In that script, write a handler that conforms to the syntax documented here for the “adding folder items to” (page 285) folder action. Your handler can use the aliases that are passed to it to access the image files dropped on the folder.
- Save the script as a compiled script or script bundle.
- Put a copy of the script in /Library/Scripts/Folder Action Scripts or
~/Library/Scripts/Folder Action Scripts.
- Use the Folder Actions Setup application, located in /Applications/AppleScript, to:
a. Enable folder actions for your image folder.
b. Add a script to that folder, choosing the script you created.
adding folder items to
A script handler that is invoked after items are added to its associated folder.
Syntax
on adding folder items to alias after receiving listOfAlias [ statement ]…
end [ adding folder items to ]
Placeholders
alias
An alias (page 98) that identifies the folder that received the items. listOfAlias
List of aliases that identify the items added to the folder.
statement
Any AppleScript statement.
Examples
The following Folder Action handler is triggered when items are added to the folder to which it is attached. It makes an archived copy, in ZIP format, of the individual items added to the attached folder. Archived files are placed in a folder named Done within the attached folder.
â—
â—
Folder Actions Reference
on adding folder items to this_folder after receiving these_items
tell application “Finder”
if not (exists folder “Done” of this_folder) then
make new folder at this_folder with properties {name:“Done”}
end if
set the destination_folder to folder “Done” of this_folder as alias
set the destination_directory to POSIX path of the destination_folder
end tell
repeat with i from 1 to number of items in these_items
set this_item to item i of these_items
set the item_info to info for this_item
if this_item is not the destination_folder and ¬
the name extension of the item_info is not in {“zip”, “sit”} then
set the item_path to the quoted form of the POSIX path of this_item
set the destination_path to the quoted form of ¬
(destination_directory & (name of the item_info) & “.zip”)
do shell script ("/usr/bin/ditto -c -k -rsrc --keepParent " ¬
& item_path & " " & destination_path)
end if
end repeat
end adding folder items to[/format]
Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) mardi 6 juin 2017 18:51:57