Conditional choosing

I’m having an annoying issue with a script I’ve been working on. When I run the following script, it allows me to choose the folder I actually choose.

set sourcefolder to alias ("/Users/*****/Documents/" as POSIX file)

set FolderSource to (choose folder of sourcefolder with prompt "Find the folder with the wrong Convention Code")	

When I use the same code with a conditional statement such as:

set sourcefolder to alias ("/Users/*****/Documents/" as POSIX file)

if buttonpressed is "Recode Existing Folder" then
		set FolderSource to (choose folder of sourcefolder with prompt "Find the file with the wrong Convention Code")	
	end if

It digs deeper into the folder structure when I choose unless I press the fn key while I hit return. I’ve read about the key down command, but that seems like cheating. Is there another way to force the first choice.?

Hi.

You should use ‘choose file’, not ‘choose folder’, if you want to choose a file. Also, the correct “default folder” syntax for both commands is ‘default location’, not ‘of’:

set FolderSource to (choose file default location sourcefolder with prompt "Find the file with the wrong Convention Code")

Hi Nigel,
Thank you for the guidance. I do want to restrict the search to folders, but I appreciate the syntax help. I’m SLOWLY learning, but at least still making some progress. It still opens the first folder rather than making it the selected folder. Is there a way to keep it from digging further?

Yeah sorry. You did say folder in your query. I was going by the prompt in the script.

I haven’t been able to duplicate your problem, but I have my own problem with the ‘choose file’ and ‘choose folder’ dialogs in Mountain Lion in that they open with the folder listing window empty! I have to switch to another folder and back again to see the contents. But this only happens with scripts run in AppleScript Editor. They’re OK in other contexts. :confused:

I’ve noticed that too (the empty folder until you leave and go back) and just assumed I needed to run Diskwarrior or disk utility.

You said you weren’t able to replicate the issue on your machine - could this be a setting on my machine or a glitch in my system? Rather than being something that makes the script unusable, it’s more something that keeps me feeling the script is finished. My scripts tend to be bits and pieces of other people’s work I’ve tried to adapt for my own needs. I’m still trying to decipher what works and why.

It seems like it. The effect you describe is what happens when the right-arrow key’s pressed, but I haven’t been able discover what might make hitting the Return key or clicking the “Choose” button do the same thing. I think the conditional statement’s a red herring. Did you actually experiment with ‘key down’? That could have left a modifier key programmatically “stuck down”. If so, logging out and back in, or restarting, may clear it. Or there are all sorts of ways of changing keyboard behaviour in System Preference. Sorry I can’t be more help than that. :frowning:

In my research though, I came across the answer to something which has been annoying me since I upgraded from Snow Leopard to Mountain Lion a few months ago ” the fact that Command-D doesn’t work as an alternative to the “Don’t Save” button in the new dialogs which have them. It turns out that the combination in these cases is Command-Delete. So thanks for that. :slight_smile:

Try switching to a different view and back. It’s not just an ASE problem…

Hi Nigel,
I wanted to thank you again for your help. I haven’t solved the issue, but tried the script on the other partition on my drive and the issue was gone, so it is a setting or glitch on this partition. I at least have a starting parting point.

Hi,

About the blank window, I used to get a lot of that, now It rarely happens. Also, I hardly change views now. It’s a strange bug.

gl,
kel

ps. running OS 10.8.4

Model: MBP
AppleScript: AS 2.2.4
Browser: Safari 536.28.10
Operating System: Mac OS X (10.8)

After a clean reinstall of my system trying to remedy the problem, I thought I had solved the issue. The script was working as I wanted it so I exported it as an application. Now the issue is back. When I try to choose a top level folder, the folder opens rather than being selected. So it’s something that takes place only as an application.

Again, this is more of an annoyance than anything, but after a all the time I’ve spent with the reinstall It’s really an annoyance.

Try wrapping the call in a tell block, like:

tell application "SystemUIServer"
set theFile to choose file
end tell

I think that what’s happening is that the main thread is being blocked by the modal call, and somehow that’s blocking other threads the open panel uses to update itself.

I just noticed something that might be relevant - when I export it as an application, it works when it seem to be in the process of formatting the application. In other words if I trigger it while the circle and slash are still over the icon it works (meaning the top level folder is selected), when the circle and slash disappear it stops.

IT WORKED!

Thank you so much!