Passing a variable to Finder

I would like to pass a value received from ASOC to finder, but can’t find the right place to enter my Tell Finder command. Here’s what the script looks like right now. I know the value is being returned because it worked in the commented-out display dialog command.

script ImpoCombineAppDelegate
	property parent : class "NSObject"
	
	property date_field : missing value
	
	on DoWithDate_(sender)
		set the input_date to date_field's floatValue()
		set adDate_value to input_date
		--display dialog adDate_value
		
set adFolder to "work Folders:Creative:Weekly_Ads_Print_"

tell application "Finder"
			open folder (adFolder & adDateValue)
		end tell
		

tell adDate_Readout to setFloatValue_(adDate_value) as text
		
	end DoWithDate_
		
	on applicationWillFinishLaunching_(aNotification)
		-- Insert code here to initialize your application before any files are opened 
	end applicationWillFinishLaunching_
	
	on applicationShouldTerminate_(sender)
		-- Insert code here to do any housekeeping before your application quits 
		return current application's NSTerminateNow
	end applicationShouldTerminate_
	
end script

If someone could help me out I’d really appreciate it… I’m trying to learn how to use ASOC and struggling to get a grasp on it. If you do know how to fix this for me, would you also mind explaining why too?

Thanks in advance!

Chrissy Barrington

Looks like you are pretty close… but your adFolder path might be wrong. I think that you need to start the path with the path to your disk. So if your disk is called “Macintosh HD,” and work folders is in the root, then you would set adFolder to “Macintosh HD:work Folders:Creative:Weekly_Ads_Print_:”

Hope that helps…

Hmm, well Work Folders is actually a server… I don’t think that’s it. I checked the finder commands in AS Editor too, and it’s fine. I’m afraid that someone is going to say you can’t actually write straight-up applescript in ASOC… please tell me I’m wrong!

I don’t know how to incorporate the other very large AS script I wrote into ASOC. Which is another question I have… Can I still use regular expressions with ASOC?

Try.

set the input_date to date_field's floatValue() as string

I tried this and it’s still not doing anything. Bummer…

What does this show in the console?

log (adFolder & adDateValue)

wow, cool trick…

it says the variable adDateValue is not defined.

but when I do the display dialog adDateValue, it gives me the number I typed in.

Try this.

set the adDate_value to date_field's floatValue() as string

Do you mean for me to add that line in or am I replacing another line with your code?

In your original script, you are not using the save variable names for the date value.
adDateValue and adDate_value

Most likely that was the issue.

Try this.

on DoWithDate_(sender)
    set adDateValue to date_field's floatValue() as string
	set adFolder to ("work Folders:Creative:Weekly_Ads_Print_" & adDateValue)

	tell application "Finder"
          open folder adFolder
    end tell

	tell adDate_Readout to setFloatValue_(adDate_value) as text
end DoWithDate_

Ok! We’re getting closer! It’s giving me this error now:

*** -[ImpoCombineAppDelegate DoWithDate:]: Finder got an error: Can’t get folder “work folders:creative:weekly_ads_print_1.211E+4”. (error -1728)

When I do a display dialog now, it’s giving me 1.211E+4 when I type in 012110

as mentioned above, the (HFS) path must start with a disk name

floatValue() returns a floating point number, better use intValue() or even stringValue()

As its a network volume your mounting you may want to try something like

afp://work folders._afpovertcp.tcp.local:creative:weekly_ads_print

Thanks for your help everyone! It turns out that my problem was not actually with the script itself. Instead, it was because of the way I connected things. I originally had not used the bindings options, but found that when I re-wrote the code to accomodate bindings, it worked beautifully.

Now I have another question… when is it proper to use bindings, and why? And when can you use the simple connecting method? Can you mix the two within the same script? I ask because the newly fixed script works if the user presses the return key, but I’m now stuck on getting the button to run the script (yeah, I’m realllly a beginner…) Do I now need to bind the button to run the script to something? I have it connected to the DoWithDate handler, but nothing else. I would like the user to have the option to either hit return or the button to get things going.

Here’s the new script if anyone is interested:

script ImpoCombineAppDelegate
	
	property parent : class "NSObject"
	
	property date_field : missing value
	
	on DoWithDate_(sender)
		
		set adDateValue to date_field as string
		set adFolder to ("work Folders:Creative:Weekly_Ads_Print_" & adDateValue)
		
		tell application "Finder"
			open folder adFolder
		end tell
		
		set my adDateValue to (date_field as text)
			
		
	end DoWithDate_
	
end script

Bindings and target-action connections do different things, so you’ll often use both. You can write apps without using bindings, but probably not without target-action connections.

If you have the button connected, that’s fine. You can assign return as a shortcut for the button in Interface Builder, or you can make DoWithDate_ the selector of the date text field, so that if you hit return in it or tab out of it, the handler is called.