Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > applescript studio droplet prefs

applescript studio droplet prefs
Thread Tools
3R1C
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jan 17, 2002, 10:42 PM
 
I've nearly completed an AS-S droplet project. What it attempts to do is this:

dropped files will have their names checked for known extension types, such as .prefpane .service .saver etc. these files will then be routed to their appropriate location. As it stands, 1 of three possible properties is named in my script. these properties act as flags to determine how the app should function.
1 - ask each time who should have access to the dropped file

2 - dont ask. put dropped files in ~/library/whatever for use by the current user only.

3- dont ask. put dropped files in /library/whatever for use by all users.

what I want to do is this:

if the user double-clicks the droplet and runs it rather than execution via dropped file, I want the user to be able to specify which way the droplet would behave (1,2, or 3). Default droplets created in project builder dont start off with a preferences... menu in the app menu of the droplet. I created one in interface builder and added a handler in my applescript, but the menu doesnt cause my preference.nib to be loaded/displayed. I have used this same method on other as-s apps, and it always works. so....

one of the following is true.

1. as-s droplets dont alow the use of menu items
2. The implementation of menu items is different in a droplet.
3. it works fine but i've made a coding error somewhere. (i've fiddled with it for 8-10 hrs over 3 days, i cant find it)

heres my code:


-- Application.applescript


--ask each time
property promptChoice : 1
--this user
--property promptChoice : 2
--all users
--property promptChoice : 3


property extension_Path : {"prefpane$PreferencePanes", "saver$Screen Savers", "Service$Services", "fcache$FontCollections", "osax$ScriptingAdditions", "qtx$ScriptingAdditions", "spz$spazface"}
property type_list : {}

property rootPath : {(((path to startup disk as string) & "library:") as string)}
property userPath : {(((path to current user folder as string) & "library:") as string)}

global item_info
global theType
global filePath
global theExtension_List
global thePath_List
global thePath
global moveToPath

on idle
(* Add any idle time processing here. *)
end idle


on open these_items
(* Add your script to process the names here. *)
set theExtension_List to {}
set thePath_List to {}
set AppleScript's text item delimiters to "$"
repeat with foo from 1 to the count of items of extension_Path
set kung to item foo of extension_Path
set the end of the theExtension_List to text item 1 of kung
set the end of the thePath_List to text item 2 of kung
end repeat
set AppleScript's text item delimiters to ""
repeat with foo from 1 to count of these_items
set this_item to item foo of these_items
set item_info to info for this_item
set theType to (name extension of item_info)
if (folder of item_info is false) and �
(alias of item_info is false) and �
((file type of item_info is in type_list) or �
(theType is in theExtension_List)) then
repeat with foo from 1 to the count of the thePath_List
if item foo of the theExtension_List is the theType then
set the thePath to item foo of the thePath_List
exit repeat
end if
end repeat
process_item(this_item)
else
display alert "Unknown file type." as critical message "The file " & (this_item as string) & " with extension <" & theType & "> is not a type I know what to do with yet."
end if
end repeat
quit
end open

on process_item(this_item)
if promptChoice is 1 then
set CurrentUser to do shell script "whoami"
set AppleScript's text item delimiters to ":"
set theName to the last text item of (this_item as string)
set AppleScript's text item delimiters to ""
display dialog "Who shall have access to the file <" & (theName as string) & ">" buttons {"Cancel", "Everyone", CurrentUser} default button 3 with icon note
set user_choice to the button returned of the result
if user_choice is CurrentUser then
UserProc()
else
if user_choice is "everyone" then
rootProc()
end if
end if
else
if promptChoice is 2 then
UserProc()
else
if promptChoice is 3 then
rootProc()
end if
end if
end if
tell application "Finder" to move this_item to (filePath as string) replacing ask

end process_item

on doesFolderExist()
tell application "Finder"
if not (exists (folder filePath)) then
make folder in folder (moveToPath as string) with properties {name:thePath}
end if
end tell
end doesFolderExist

on UserProc()
set moveToPath to userPath
set filePath to (userPath & thePath & ":") as string
doesFolderExist()
end UserProc

on rootProc()
set moveToPath to rootPath
set filePath to (rootPath & thePath & ":") as string
doesFolderExist()
end rootProc


property preferencesWindow : null


on choose menu item theObject
-- Only load the preferences nib once
display dialog (menu item)
--if menu item is "Preferences" then
if preferencesWindow is equal to null then
load nib "Preferences"
set preferencesWindow to window "preferences"
end if
-- Load in the preferences
loadPreferences(preferencesWindow)

-- Show the preferences window
set visible of preferencesWindow to true


on clicked theObject
if name of theObject is "done" then
-- Save out the preferences
storePreferences(preferencesWindow)
end if

-- Hide the preferences window
set visible of preferencesWindow to false
end clicked

on action theObject
(*Add your script here.*)
end action

on became main theObject
(*Add your script here.*)
end became main

on will open theObject
(*Add your script here.*)
end will open

on changed theObject
(*Add your script here.*)
end changed

on update menu item theObject
(*Add your script here.*)
end update menu item

on loadPreferences(theWindow)
set thePopup to call method "defaultObjectForKey:" with parameter "popup"
tell theWindow
set contents of popup button "popup" to thePopup
end tell
end loadPreferences

on storePreferences(theWindow)
tell theWindow
set thePopup to contents of popup button "popup"
end tell
call method "setDefaultObject:forKey:" with parameters {thePopup, "popup"}
end storePreferences
3R1C
     
3R1C  (op)
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jan 21, 2002, 08:33 PM
 
nobody knows anything about this? Well thats a first for me. I've stumped MacNN (end veiled attempt to get response)
3R1C
     
bewebste
Senior User
Join Date: Mar 2000
Location: Ithaca, NY
Status: Offline
Reply With Quote
Jan 22, 2002, 03:08 PM
 
I just noticed in your code that there doesn't seem to be a line saying "end choose menu item". I would think that you'd get a compile error if this were so - did it just not get pasted in correctly?
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 01:19 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,