using Shane’s method, i 've a filelist (drop file on icon) in the main script.
Because i want to have a very clear program, i’ve made a different script (classes) for every function.
So here is my problem. Because the Drop file need to be on the main script, i would like, when dropping file on the app, open a new window and give the new script (classes) the filelist
on the main script, i have
on application_openFiles_(theApp, fileList) -- Concerne le renamer
log fileList
my closeActiveWindow()
my openNewWindow(renommerWindow)
end application_openFiles_
so when it open the new window “renommerWindow”, i want to be able to get the “filelist” and after i can work with this list and make all the modification i want.
Thanks for answer ;)
First, you need to make fileList a property. Then you can access it from other classes like this:
set fileList to current application's NSApp's delegate()'s fileList
If you make instances of your script classes, you can also connect them in Interface Builder.
Sorry Shane but it doesn’t work.
here is the error :
" *** -[RenameFile refreshListeFichier:]: Can’t get fileList of «class ocid» id «data kptr00000000E09E2D0002000000». (error -1728)"
in my main script (CPo_ToolBoxAppDelegate) , i defined:
property fileList : missing value – will contain list of dropped items
in the second script (RenameFile), i defined a button
on refreshListeFichier_(sender)
set fileListTransfert to current application's NSApp's delegate()'s fileList
log "-------" & fileListTransfert
end refreshListeFichier_
Other question : how can i do this action without cliking on the button but just automatically when the window open ?
Thanks
I’m not sure why it doesn’t work the way you have it, but if you put parentheses after fileList it works for an empty list but gives me a different error with a filled list – this problem has to do with the log statement. The problem goes away if I just log fileListTransfert (without the “-------”). So this works:
on refreshListeFichier_(sender)
set fileListTransfert to current application's NSApp's delegate()'s fileList()
log fileListTransfert
end refreshListeFichier_
Putting the parentheses after fileList makes it so you are accessing the property though its getter method rather than directly, which is probably the better way to do it any way.
As for your second question, how are you opening the window?
Ric
Thanks.
it wasn’t still working but i found a solution.
in the main script:
on application_openFiles_(theApp, fileList) -- Concerne le renamer
set fichierDepose to {}
log fileList
repeat with monItem in fileList
copy monItem to end of fichierDepose
end repeat
my closeActiveWindow()
my openNewWindow(renommerWindow)
end application_openFiles_
so in fact i create a new list by copying each element of “fileList” and now it works fine.
For the method about opening window :
i have a window with button. each one open a specific window by calling an handler with parameter the name of the window
on openNewWindow(newWindow)
newWindow's orderFront_(me)
set activeWindow to newWindow
activeWindow's makeKeyAndOrderFront_(me)
activeWindow's |center|()
end openNewWindow
It does – but you have to remember that the result is coming from what is effectively a Cocoa method, so you have to coerce the result to use it as an AS value.
I don’t know why it didn’t work for you, it worked for me when I tested it.
I think what you’re actually doing here is a hard way to change an NSArray (which is what fileList is) to an applescript list. You should be able to do the same thing just by saying " set fichierDepose to fileList as list".
Ric