I have written a total of two AS apps in my life, the first makes the mac say “Hello World.” and the second opens a program and changes its settings to my custom settings.
This is my third and it’s way over my head. I am trying to write a folder action app that does the following: (i know you guys don’t like folder actions, but i need to keep things as simple as possible)
-
When a file is added to the folder (dropbox), a dialog needs to display containing two dropdown menus. The first should be a dynamic list of folders in a pre-specified directory. The second should be a dynamic list of folders in the directory specified by dropdown menu 1. (I may add a third iteration of this, but once i know how to do 1 and 2, i should be able to add number 3-possibly even dynamically, based on if there are subfolders in #2.)
-
Once the user makes thier selections and clicks OK, then i need the file they added to the dropbox to be carted off to the directory specified in the dropdown menus.
I know this sounds just like saying “file > save as”, but the idea is to dumb it down as much as possible because my directory structure is very deep, and my users are having trouble remembering how to get to the parent folder (where the first dynamic list will be pulled from).
You guys rock! Thanks in advance for any and all help.
bsdmohan
There are planty of ways to display interfaces like you are talking about with Applescript… but not from Apple. The built in set of dialogs isn’t very good, and I don’t think you can write an Applescript Studio folder action. You could pick out Pashua or some other thing to create the UI you desire however a thought occurs… If th problem is just finding a folder, and to represent that folder you want to put a folder on their desktop (or somewhere close at hand), why not just create a link or alias to the folder in the place you were going to put the drop box… you could even re-name it drop box and give it a nice icon… to create a mac style alias,hold command-option and drag the folder to the desktop (or where-ever)… to create a unixy link, open up your terminal and type the command ‘ln -s /path/to/source /path/to/destination’ for example ‘ln -s /Users/Shared/Documents/DropBox/ ~/Desktop/DropBox’ (note if you have spaces don’t forget to escape them with “”)
I understand what you’re saying about the lack of interface possibilities with Script Editor…and I just now got Applescript Studio, and am trying to figure out how to use that as we speak. What I’m thinking might work, is a combination that goes something like this.
when a file is added to dropbox, it activates a folder action script written in Script Editor that in turn runs an AS designed in AS Studio, complete with interface. The AS Studio program terminates when the OK is clicked, and then somehow returns the resulting path back into the folder action script.
I am somewhat familiar with programming, but as stated before, AS is almost totally new to me, and I’m finding the AS Studio to be difficult to figure out.
bsdmohan
Instead of a folder action, how about an Applescript Studio droplet. You could make its icon look like a folder if you like too…
basic steps for a droplet:
- create a new project with the Applescript Droplet template.
2)(optional) open the nib and add a window (check the show window on launch checkbox), add extra views, customize layout, set up applescript handlers and names
- write the script (maybe get the open handler to set a script property with all the names, and in a button’s click handler use that property to read the data, act and exit)
I still think if finding the folder is the problem that it’s easier to add an alias to the desktop, dock, finder side bar, or finder toolbar… and if navigating deeper is a problem to use column view
I would agree with you if it were for a single or even just a handful of users. However, this is something that 300+ people may be using…I don’t want to try and explain to 300 people how to do that, or do it for them. Trust me, this is the simpler solution for a group of mostly computer illiterate folks.
Basically the scenario is that we have a WAN, all of which can access this server. We want information to be placed in the appropriate spots…with as little room for error as possible.
Not to be hostile or anything…I really appreciate your help
bsdmohan
Thanks to all who offered suggestions, all were considered and came in handy at different times.
Here is the application.applescript file of the Droplet that solved my problem. I wrote this with much help from this forum, and with intuition from my previous programming experiences.
The following code controls a NIB with 5 dropdown boxes, an OK and a Cancel button.
The “pathExists” function is because the directory structure in this is on a server.
Here’s the long awaited code.
global rootPath, myPath --home and dynamic paths
global select1, select2, select3, select4, select5 --selections to be made
global filename --name of file passed in to droplet
---------------------
--When Prog is run...
on open names
set rootPath to "your:path:goes:here:"
if not pathExists(rootPath) then
display dialog "Connect to the server then try again." buttons {"OK"} default button 1
quit
else
--Preliminary window settings
set myPath to rootPath as string
set filename to names as alias
show window "DropBox"
set enabled of button "GO" of window "DropBox" to 0 --Disables GO
repeat with i from 1 to 5 --for loop
set enabled of popup button ("ddown" & i as string) of window "DropBox" to 0 --disable all menus
delete every menu item of menu of popup button ("ddown" & i as string) of window "DropBox" --clear all menus
end repeat
--setup ddown1 menu items
tell application "Finder" to set select1_names to name of folders of folder rootPath --gets a list of the folders in rootPath
repeat with i from 1 to (length of select1_names)
set current_item to (item i of select1_names) as string --moves through the list 1 at a time
make new menu item at end of menu of popup button "ddown1" of window "DropBox" with properties {title:current_item, enabled:true} --creates the menu item
end repeat
set enabled of popup button "ddown1" of window "DropBox" to 1 --enables the menu
end if
end open
--------------------------------------------------------------------------------------------------
--SELECTIONS
on choose menu item theObject
if the name of theObject is "ddown1" then --when a selection from ddown1 is made...
set select1 to title of theObject as string --sets the menu selection to select1
set myPath to (rootPath & select1 & ":") as string --changes myPath to include selections
createMenu("ddown2", "ddown3", "ddown4", "ddown5") --makes ddown2, and enables/disables other menus appropriately
else if the name of theObject is "ddown2" then
set select2 to title of theObject as string
set myPath to (rootPath & select1 & ":" & select2 & ":") as string
createMenu("ddown3", "ddown4", "ddown5", "")
else if the name of theObject is "ddown3" then
set select3 to title of theObject as string
set myPath to (rootPath & select1 & ":" & select2 & ":" & select3 & ":") as string
createMenu("ddown4", "ddown5", "", "")
else if the name of theObject is "ddown4" then
set select4 to title of theObject as string
set myPath to (rootPath & select1 & ":" & select2 & ":" & select3 & ":" & select4 & ":") as string
createMenu("ddown5", "", "", "")
else if the name of theObject is "ddown5" then
set select5 to title of theObject as string
set myPath to (rootPath & select1 & ":" & select2 & ":" & select3 & ":" & select4 & ":" & select5 & ":") as string
set enabled of button "GO" of window "DropBox" to 1
end if
end choose menu item
--------------------------------------------------------------------------------------------------
--BUTTONS
on clicked theObject
if the name of theObject is "btncncl" then --on click "Cancel", quit DBox
quit
else if the name of theObject is "GO" then --on click "GO"...
tell application "Finder"
move filename to folder myPath --move the file to myPath
end tell
hide window "DropBox"
display dialog ("Your file has been copied to " & myPath) buttons {"OK"} default button 1 --confirmation dialog
quit --quit DBox
end if
end clicked
--------------------------------------------------------------------------------------------------
on idle theObject
end idle
--FUNCTIONS
to MoreExists(folder1) --bool function to see if there are subfolders in folder1
tell application "Finder" to set count_folders to count folders of folder folder1
if count_folders = 0 then
return false
else
return true
end if
end MoreExists
------
to pathExists(path1) --bool function to see if a particular path exists
set path1 to path1 as Unicode text
if path1 does not contain ":" then set path1 to POSIX file path1 as Unicode text
try
alias path1
return true
end try
false
end pathExists
------
to createMenu(ddown_next1, ddown_next2, ddown_next3, ddown_next4) --creates menu "ddown_next", and disables subsequent menus
if MoreExists(myPath) then --are there subfolders?
set enabled of popup button ddown_next1 of window "DropBox" to 1 --enable next menu
delete every menu item of menu of popup button ddown_next1 of window "DropBox" --clear the menu
tell application "Finder" to set select_names to name of folders of folder myPath
repeat with i from 1 to (length of select_names) --make the menu out of folders in myPath
set current_item to (item i of select_names) as string
make new menu item at end of menu of popup button ddown_next1 of window "DropBox" with properties {title:current_item, enabled:true}
end repeat
else --if no subfolders
set enabled of button "GO" of window "DropBox" to 1 --enable "GO" button
try --disable other menus
set enabled of popup button ddown_next1 of window "DropBox" to 0
set enabled of popup button ddown_next2 of window "DropBox" to 0
set enabled of popup button ddown_next3 of window "DropBox" to 0
set enabled of popup button ddown_next4 of window "DropBox" to 0
end try
end if
end createMenu