Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Atomant669

macrumors regular
Original poster
Oct 28, 2011
115
4
Possible to open and create an excel or word document in a folder instead of going the long route of clicking on the Document icon, 'new sheet' and 'save as'?

Appreciate any help.
 
Power users utilize keyboard shortcuts.
In this case cmd+n followed by shift+cmd+s
 
I wish that was a feature myself. I use the following workaround though it is a little clunky.

When saving a new document in Excel, you can drag the folder from the finder and drop it on the save dialog box. I first type the name of the file in the Save As: field, then drag the folder from the path bar of the folder I have open.
 

Attachments

  • 1.png
    1.png
    606.9 KB · Views: 296
  • 2.png
    2.png
    663.1 KB · Views: 271
Thanks Bernuli, I think that's what exactly I am doing now.

I am looking to just create an 'excel' or 'word' document right from the Folder where I want to save it at.

I guess there's no other 'efficient' way around this huh?
 
Thanks Bernuli, I think that's what exactly I am doing now.

I am looking to just create an 'excel' or 'word' document right from the Folder where I want to save it at.

I guess there's no other 'efficient' way around this huh?


Don't think so, not that I know of anyway.

I still find myself right clicking in the folder I am in, hoping to see "create new Excel file here" but I never see it.
 
Power users utilize keyboard shortcuts.
In this case cmd+n followed by shift+cmd+s
That's what I use, I prefer the keyboard shortcuts where ever possible, and in some cases I use macros to automate certain tasks and assign those to a keyboard shortcut as well.
 
Actually, this doable with Applescript. This version below pretty simple, but I'll add prompting for file name.


tell application "Finder"
set currentDir to (target of front Finder window) as text
end tell

tell application "Microsoft Excel"
set myWorkbook to make new workbook
save workbook as myWorkbook filename currentDir & "saveasme"
end tell
 
Ok, so here is an applescript you can put into Automator. When you start up Automater, select service for your type of document.

Drag the action "Run AppleScript" to the workflow panel.

Then paste in the following

tell application "Finder"
try
set currentDir to (target of front Finder window) as string
on error
set currentDir to path to desktop folder as string
end try
end tell

display dialog "Specify file name: " & currentDir default answer ""
set fileNameYo to the text returned of the result

tell application "Microsoft Excel"
activate
set myWorkbook to make new workbook
save workbook as myWorkbook filename currentDir & fileNameYo & ".xlsx"
end tell

Once you do that you can assign the service a keyboard shortcut that is accessible in the finder window you are in.



automater.png
keyboardPref.png
 
Here is an AppleScript that will prompt you to choose Excel Word or PowerPoint. Runs as a keyboard shortcut (as a Service) for me in Finder to problem.

I must be reinventing the wheel here. Surely someone has a script better than this.



---- Applescript to create a new Microsoft Office 2011 document within the frontmost opened folder in the Finder.
---- User is prompted for a file name. If the specified file already exists, script terminates to ensure that an existing file will not be overwritten. (Word save as AppleScript command clobbers by default.)

---- Get the frontmost Folder that is open in the Finder. Use Desktop if no windows open.
tell application "Finder"
try
set currentDir to (target of front Finder window) as string
on error
set currentDir to path to desktop folder as string
end try
if currentDir = "" then set currentDir to path to desktop folder as string

end tell


---- Choose which application new document will be for.
set applicationList to {"Excel", "Word", "PowerPoint"}
activate
choose from list applicationList with prompt "Choose Application" default items "Excel"
set applicationChoice to result as text

---- Prompt user for file name.
display dialog "Location will be:" & linefeed & linefeed & currentDir & linefeed & linefeed & "Please choose a name for new " & applicationChoice & " document:" & linefeed & linefeed default answer ""
set fileNameYo to the text returned of the result

if fileNameYo = "" then
display dialog "No file requested."
return "nothing done"
end if

---- Append application extension to specified file name according to applicationChoice.
if applicationChoice = "Excel" then set fileNameYo to fileNameYo & ".xlsx"
if applicationChoice = "Word" then set fileNameYo to fileNameYo & ".docx"
if applicationChoice = "PowerPoint" then set fileNameYo to fileNameYo & ".pptx"

---- First make sure reqested file does not exist, ignore case in comparison. If file exists, script terminates with no action taken.
set pathAndName to currentDir & fileNameYo

tell application "Finder"
ignoring case
if exists file pathAndName then
display alert "ERROR! File already exists." & linefeed & linefeed & pathAndName & linefeed & linefeed & "Exiting."
return "nothing done"
else
display dialog "This new " & applicationChoice & " document will be created:" & linefeed & linefeed & pathAndName

end if
end ignoring
end tell


---- Create new document file using the Application chosen in applicationChoice

if applicationChoice = "Excel" then
tell application "Microsoft Excel"
activate
set myWorkbook to make new workbook
save workbook as myWorkbook filename pathAndName
end tell
end if

if applicationChoice = "Word" then
tell application "Microsoft Word"
activate
create new document
save as active document file name pathAndName
end tell
end if

if applicationChoice = "PowerPoint" then
tell application "Microsoft PowerPoint"
activate
set myPres to make new presentation
save myPres in pathAndName
close myPres
open pathAndName
end tell
end if
 
Last edited:
You can also drag and drop the desirable folder onto the "save as" dialog to avoid navigating to it...
 
Ok, so here is an applescript you can put into Automator. When you start up Automater, select service for your type of document.

Drag the action "Run AppleScript" to the workflow panel.

Then paste in the following

tell application "Finder"
try
set currentDir to (target of front Finder window) as string
on error
set currentDir to path to desktop folder as string
end try
end tell

display dialog "Specify file name: " & currentDir default answer ""
set fileNameYo to the text returned of the result

tell application "Microsoft Excel"
activate
set myWorkbook to make new workbook
save workbook as myWorkbook filename currentDir & fileNameYo & ".xlsx"
end tell

Once you do that you can assign the service a keyboard shortcut that is accessible in the finder window you are in.



View attachment 604048 View attachment 604049

Hi, thanks for your script. It's work very well.

I want to improve that script as follows.
1/ Creating new files will be the same as on Windows.
2/ After creating the Excel File, close the current Workbook and close the Excel program.
3/ The Excel program will not close if another file is open.

I have tried and succeeded with 1, 2. As for the 3rd problem, please see and help me.

My Script:

AppleScript:
tell application "Finder"
    try
    set currentDir to (target of front Finder window) as string
    on error
    set currentDir to path to desktop folder as string
    end try
end tell

display dialog "Specify file name: " & currentDir default answer ""

set fileNameYo to the text returned of the result
tell application "Microsoft Excel"
    activate
    set myWorkbook to make new workbook
    save workbook as myWorkbook filename currentDir & fileNameYo & ".xlsx"
    close active workbook
    quit
end tell

4. I want file name is auto by tempalate untitle-{number}.xlsx
If create .txt by bash I use script

Bash:
DIR="$1"
FILE="$DIR/untitled.txt"
COUNTER=1


while [[ -e $FILE ]]; do
  FILE="$DIR/untitled-$COUNTER.txt"
  ((COUNTER++))
done


touch "$FILE"
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.