User Name
Password
AppleNova Forums » Genius Bar »

My first applescript, final touches?


Register Members List Calendar Search FAQ Posting Guidelines
My first applescript, final touches?
Thread Tools
Koodari
Veteran Member
 
Join Date: Jun 2004
 
2004-09-07, 20:29

I got inspired by nassau's 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.
Code:
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 tell
There 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.)
  quote
nassau
Member
 
Join Date: Jul 2004
 
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..
  quote
Koodari
Veteran Member
 
Join Date: Jun 2004
 
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.
Code:
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
  quote
staph
Microbial member
 
Join Date: May 2004
Send a message via AIM to 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.
  quote
Posting Rules Navigation
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Post Reply

Forum Jump
Thread Tools
Similar Threads
Thread Thread Starter Forum Replies Last Post
Emergency Final Cut Pro Help ast3r3x Apple Products 6 2004-06-10 11:09
Final questions before I get an iBook. Wickers Apple Products 21 2004-06-09 22:15


« Previous Thread | Next Thread »

All times are GMT -5. The time now is 10:20.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004 - 2024, AppleNova