What's wrong with this simple folder action script? - help

ok, I got back to applescript after a couple of years without it (was using it before OSX) to find it more frustrating than ever. I’m trying to make a folder script but this script doesn’t work:


on adding folder items to this_folder after receiving added_items
	tell application "Finder"
		display dialog "1"
		set the folder_name to the name of this_folder
		display dialog "2"
	end tell
end adding folder items to

I’ve got the first dialog but never the second

Thanks for any help.

Max.

I’m getting both dialogs. Are you hitting the “Cancel” button to dismiss the first dialog? The Cancel button of a “display dialog” dialog automatically throws a “user canceled” error, which silently causes script execution to halt.

No, I’m hitting the “ok” button. That’s why it’s so frustrating. It seem that AppleScript with OS X doesn’t work too well, I never had problems like that before.

And since I based the code on some code I saw in this forum I though that is was working fine. I had a whole page or two for my script and wondering what was wrong, since it did nothing, I choped it and put some dialog to debug it. And now I reduced it to that:

on adding folder items to this_folder after receiving added_items
	tell application "Finder"
		set the folder_name to the name of this_folder
		display dialog "2"
	end tell
end adding folder items to

and now nothing happen at all…

I’ll rebbot and see if it change something…

Max

It doesn’t work better after I rebooted. I just checked on another computer, and it’s seem to work fine.

So, on a 400 MHz PowerPC G4 Mac OS X 10.3.3 Build 7F44 with AppleScript FUI-1.9.3 it doesn’t work, but on a 400 MHz PowerPC G4 Mac OS X 10.2.8 Build 6R73 with AppleScript 1.9 it’s working.

Any idee why? Both system are in French but I guess it souldn’t change anything.

Anyway, I’ll try tonight at home with 10.3.3 and see what happen…

Max.

I tried at home and it doesn’t work too.

OS X 10.3.3
Build 7F44
AppleScript FU1-1.9.3

could it be OS X 10.3.3?

Max.

Switching to english, adding an ‘on error’ and displaying it, I get the following message:

Finder got an error: Can’t get name of alias “max:folder”.

Max.

Hmm… I’m just making a wild guess, but do the folders have any unusual Unicode characters in them?

Ok, I tried a couple of things and it seem I cannot use folders that are in my home folder and since I was working with a folder that usualy is on my home folder or desktop folder, when I put it outside my home folder it worked…

Ok, I just tried to do it with another user, my previous user was ‘Max’ on a volume named ‘Monkey’, and with the new user (Dev) it work.

If I add a dialog showing the path of the folder (right after the tell application ‘finder’), with the user Max, I get “Max:folder”. If I drop the same folder on a terminal window, I get “Users/max/folder”.

If I do the same thing with the user ‘Dev’ I get ‘Monkey:Dev:folder’ dialog

Why does the volume doesn’t apprear with the user ‘Max’?
Souldn’t OS X know what folder I’m talking about with the user ‘Max’?
Is ‘Max’ not a good user name?
Does OS X got confused?

Any way to work around this situation?

For now I’ll work outside my home folder. Is there a rule saying it’s best not to work in your home folder?

Thanks

Max.

The change in case is interesting, from Max to max. I can’t image what the problem is here. Perhaps an explicit coercion from alias to Finder object might help:


on adding folder items to this_folder after receiving added_items

    tell application "Finder"

        set this_folder to folder this_folder

        -- OR: set this_folder to folder (this_folder as string)

        set folder_name to name of this_folder 

      display dialog (folder_name)

   end tell 
end adding folder items to

Sorry, the change in case … that was my error.

As for the code, same thing. It run correctly if not somewhere in my home folder otherwise I get :

Finder got an error: Can’t get name of folder “folder” of item “max”

And again with user ‘Dev’ everything’s ok.

I found it!

It’s FileVault. it’s activated for the user Max but isn’t for the user ‘Dev’.

I logged on with Dev, attach a script to a folder on the desktop and tried it: everything’ok.
I activate FileVault, the script is no more attached to the folder, I reattached it and get the error…

Disactiving FileVault make it work again!

Thanks for the help.

Good stuff. :slight_smile:

My next suggestion was going to be that you look at your Unix permissions… but that is a topic outside my field of expertise.

Hi Max,
you probably have a owner problem. This comes up when you are using data and folders which have already been used in MacOS9 because they did not have any owner. Items with NO owner atomatically belong to “System”. When you put your folder inside your “documents” folder you must change permissions for this folder and all folders inside. Do the following:

  • Make sure to have your administrator password available.
  • Open the Terminal which is in the Utilities folder inside your applications folder.
  • Type the following : sudo chown -R yourUsername (notice the blanks and put in your real username). Hit the enter key. You will see a password request. Put in your administrator password and hit the enter key again.
    This is what it means:
    sudo (gives you administrator rights to do certain things, not always necessary)
    chown (means change owner)
    -R (option to apply the command to the complete hierarchy of the folder)
    Eventually you you have to set permissions:
  • Type the following : sudo chmod -R u=rwx,o=rwx,g=rwx yourFolderPath
    You may put in the folder path by dragging the folder into the terminal to the insertion point.
    This is what it means:
    sudo (gives you administrator rights to do certain things)
    chmod (means change mode)
    -R (option to apply the command to the complete hierarchy of the folder)
    u=rwx (User: read write execute)
    o=rwx (Owner: read write execute)
    g=rwx (Group: read write execute)

Have fun, Ronald, Germany

[quote=“Mr.Max”]
Ok, I tried a couple of things and it seem I cannot use folders that are in my home folder and since I was working with a folder that usualy is on my home folder or desktop folder, when I put it outside my home folder it worked…

Ok, I just tried to do it with another user, my previous user was ‘Max’ on a volume named ‘Monkey’, and with the new user (Dev) it work.

Thanks, but I already know about those commands.

But, for the folder, I created it in OS X and I have Admin privilege. Are the scripts using the current user privilege by the way?

And moving the folder shouldn’t change the permission right? but when I moved the folder outside my home, the script worked.

And as I said, just activating/desactivating FileVault made the script not work/work. So I guess FileVault is changing some permission or other…

anyway
Thanks.

Max.