PDA

View Full Version : My first applescript, final touches?


Koodari
2004-09-07, 20:29
I got inspired by nassau's (http://forums.applenova.com/showthread.php?t=1580) scripting "project" and decided to try out the scripting and script a feature I missed from Windows. Namely, an easy way to create a new empty file while browsing a folder, so you can then drag it to an application and start editing without opening the application and navigating to same folder again.

I installed the developer stuff and found that using the plentiful examples, this script was very easy to make. I compiled it into an app and dragged that into Finder toolbar. Then it's always there, you just click it and it asks you for the filename to create.
tell application "Finder"
set the new_file_name to ""
display dialog "Enter the name for new file:" default answer the new_file_name buttons {"Cancel", "OK"} default button 2
copy the result as list to {the new_file_name, the button_pressed}
set the current_folder to (folder of the front window) as alias
do shell script "touch \"" & POSIX path of current_folder & new_file_name & "\""
end tellThere is one thing that the script really needs but don't know how to do it. Now the file doesn't appear right away, I need to navigate away and back into the folder. Do you know how to refresh the Finder window to make the file immediately visible? I'm guessing any file manipulation using Finder itself would force the refresh, but I'd like to know there is no better way before I try the hack.

Also, is Applescript Studio the same as Script Editor, or the same as XCode? The documentation talks about Applescript Studio but I have only found the latter two. (scratch that question - I read developer docs and it seems Applescript Studio is roughly XCode, Interface Builder and some frameworks.)

nassau
2004-09-07, 22:40
perhaps after the file has been created, the script can "rename" it. maybe this will force a refresh..?

i'm clueless tho..

Koodari
2004-09-08, 12:37
Fixed it. Now it's as good as I hoped. I still don't know where to look for reference of a certain program's (Finder in this case) scripting features, didn't find any from Mac Help, or by browsing the developer documentation. I found the refresh code with a web search.

tell application "Finder"
set the new_file_name to ""
display dialog "Enter the name for new file:" default answer the new_file_name buttons {"Cancel", "OK"} default button 2
copy the result as list to {the new_file_name, the button_pressed}
set the current_folder to (folder of the front window) as alias
do shell script "touch \"" & POSIX path of current_folder & new_file_name & "\""
tell front window
update every item with necessity
end tell
end tell

staph
2004-09-08, 12:46
Open /Applications/Script Editor.app, File>Open Dictionary (cmd-shift-O), find the application you want, and select it. It'll present you with a fairly basis representation of that program's exposed Applescript functionality.