• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: New File Here
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New File Here


  • Subject: Re: New File Here
  • From: "koenig.yvan" <email@hidden>
  • Date: Fri, 26 Oct 2012 10:23:35 +0200


Le 26/10/2012 à 09:06, Christopher Stone <email@hidden> a écrit :

Hey Folks,

There are a few utilities out there to create a new file of a specific file-type in the front directory in the Finder.

Today I needed something like that, so I wrote a simple one.

You just create templates of any desired file-type in the New_File_Here! folder (the script will create it if it doesn't exist and reveal it in the Finder).

You get a choose-from dialog with the file templates and can go to town from there.

Multiple selections are supported.

I chose to select the newly created file in the Finder for renaming rather than fooling with another Applescript dialog.

--
Best Regards,
Chris

------------------------------------------------------------------------------------------------
#       Author: ccs
#      Created: 2012-10-26 : 01:27
#     Modified: 2012-10-26 : 01:40
#  Application: Finder 
#      Purpose: Create a new file from a file-type list in the front Finder window.
# Dependencies: None
------------------------------------------------------------------------------------------------

try
  
  try
    set templateFolder to ((path to application support from user domain as text) & "Script_Support:New_File_Here!:")
    set templateFolder to alias templateFolder
  on error
    set _temp to quoted form of (POSIX path of templateFolder)
    do shell script "mkdir " & _temp & "; open -R " & _temp
    return
  end try
  
  tell application "Finder"
    if front window exists then
      set winTarget to target of front window as alias
    else
      error "No windows open in Finder!"
    end if
  end tell
  
  set fileTemplateList to list folder templateFolder
  
  set fileType to choose from list fileTemplateList with title "New_File_Here! Templates" with prompt ¬
    "Pick One:" default items {get item 1 of fileTemplateList} with multiple selections allowed
  
  if fileType ≠ false then
    set _file to alias ((templateFolder as text) & fileType)
    tell application "Finder"
      duplicate _file to winTarget
      select ((winTarget as text) & fileType)
    end tell
  end if
  
on error e number n
  set e to e & return & return & "Num: " & n
  tell me to set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
  if button returned of dDlg = "Copy" then set the clipboard to e
end try

--

Hello Christopher

(1) Is it a good idea to create a new script relying upon list folder which is deprecated ?

(2) We may select several items in the choose file dialog but if we do that, the script fails with the error message :
  the file "the:folder:New_File_Here! Templates:firstemplate.jpgsecondtemplate.tiff: is unavailable.


Yvan KOENIG (VALLAURIS, France) vendredi 26 octobre 2012 09:41:45




 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: New File Here
      • From: Christopher Stone <email@hidden>
    • Re: New File Here
      • From: Christopher Stone <email@hidden>
References: 
 >New File Here (From: Christopher Stone <email@hidden>)

  • Prev by Date: New File Here
  • Next by Date: Re: set clipboard fails
  • Previous by thread: New File Here
  • Next by thread: Re: New File Here
  • Index(es):
    • Date
    • Thread