dialog buttons in Applescript Studio

dialogs in Applescript Studio

Hello,

is there some special way to deal with dialogs’ button returned in ASS?

I’ve been working on developping a little application for myself regrouping scripts by apple (like file renaming and stuff), and it seems that the dialog doesnt return the answer of the button clicked !

I get an error all the time : “No result was returned from some part of this expression. (-2763)”…

Here is my code:

on clicked theObject
	
	
	if (name of theObject is "btnGo") then
		
		tell window "main"
			set textToFind to contents of text field 1
			set textToWrite to contents of text field 2
		end tell
		
		if (textToFind = "") then
			display dialog "
Please enter text to find !" attached to window "main" with icon 1 buttons {"OK"} default button {"OK"} giving up after 3
		else
			if textToFind is textToWrite then
				display dialog "Text to Find is the same as Text to Replace :  

Please modify the replacement text..." attached to window "main" buttons {"OK"} default button {"OK"} giving up after 3 with icon 1
				
			else
				if textToFind is not textToWrite then
					
					--================================ RENAME FILES ========================================
					if state of button "renameFiles" of drawer "drawer" of window "main" is 1 then
						
						
						set source_folder to choose folder "Choose the files you want to rename :" with multiple selections allowed 
						
						set search_parameter to button returned of (display dialog "Search and replace in:" buttons {"File Names", "Folder Names", "Both"} default button 3)
						
						repeat
							if the textToWrite contains ":" then
								beep
								display dialog "A file or folder name cannot contain a colon (:)." buttons {"Cancel", "OK"} default button 2
							else if the textToWrite contains "/" then
								beep
								display dialog "A file or folder name cannot contain a forward slash (/)." buttons {"Cancel", "OK"} default button 2
							else
								exit repeat
							end if
						end repeat
						set the item_list to list folder source_folder without invisibles
						set source_folder to source_folder as string
						repeat with i from 1 to number of items of the item_list
							set this_item to item i of the item_list
							set this_item to (source_folder & this_item) as alias
							set this_info to info for this_item
							set the current_name to the name of this_info
							set change_flag to false
							if the current_name contains the textToFind then
								if the search_parameter is "Folder Names" and ¬
									folder of this_info is true then
									set the change_flag to true
								else if the search_parameter is "File Names" and ¬
									folder of this_info is false then
									set the change_flag to true
								else if the search_parameter is "Both" then
									set the change_flag to true
								end if
								if the change_flag is true then
									-- replace target string using delimiters
									set AppleScript's text item delimiters to the textToFind
									set the text_item_list to every text item of the current_name
									set AppleScript's text item delimiters to the textToWrite
									set the new_item_name to the text_item_list as string
									set AppleScript's text item delimiters to ""
									my set_item_name(this_item, new_item_name)
								end if
							end if
						end repeat

end if .. blah blah

Any way you could give me some pointers ?

Thanks in advance…

EDIT | just to be clear, I get the error right around this part :

set search_parameter to button returned of (display dialog "Search and replace in:" buttons {"File Names", "Folder Names", "Both"} default button 3)

The dialog doesnt recognize the button that I click (“File Names”, “Folder Names” or “Both”)…

Hi BSOD,

I have been playing with your script a little and I don’t think the error is from the display dialog. It is coming after that. I have found that it is the repeat statement.

I changed it to


repeat with i from 1 to (count of the item_list)

instead of


repeat with i from 1 to number of items of the item_list

I also changed this bit as well


set this_item to (source_folder & this_item) as alias

to this


set this_item to (source_folder & this_item as string) as alias

Dallas

awesome, i dont get the error anymore…

however the search and replace script still doesnt work… and I dont see whats keeping it from working. I have verified every aspect of the code, and technically, it should change the file names no questions asked …

could you explain rapidly how the parenthesis change the error thing ? Im not getting the difference between what you changed and what is already in the script ?

Thanks so much for your help :smiley:

EDIT:
OK, I’ve been playing around with the rest of my code a little, and I moved some stuff around and it does work now. :wink: