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.)
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.)