Esta tarea es muy sencilla con AppleScript en Excel de Office 2011.
(Actualmente no puedo confirmar que funcione con Office 2016.)
----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/11/28 15:34
# dMod: 2017/11/28 15:39
# Appl: Microsoft Excel
# Task: Get the front document's container folder path & its full path.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Microsoft_Excel, @Front, @Document, @Container, @Folder, @Path, @Full, @Path
# Test: Tested only in Excel 14.7.1 (of Office 2011) on macOS 10.12.6
----------------------------------------------------------------
tell application "Microsoft Excel"
tell front document
set docContainerPathHFS to path
set docFullPath to full name
end tell
end tell
set the clipboard to docFullPath
----------------------------------------------------------------
Puede obtener la ruta a la carpeta contenedora del documento o su ruta completa.
Aquí hay otra técnica que utiliza el UI-Scripting que funciona con la mayoría de las aplicaciones, incluso si NO son compatibles con scripts. (He agregado el manejo de errores a este).
----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/11/28 15:25
# dMod: 2017/11/28 15:30
# Appl: Microsoft Excel, System Events
# Task: Copy path of frontmost Excel document to the Clipboard.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Microsoft_Excel, @System_Events, @Copy, @Path, @Frontmost, @Excel, @Document, @Clipboard
# Test: Tested only in Excel 14.7.1 (of Office 2011) on macOS 10.12.6
----------------------------------------------------------------
use AppleScript version "2.4" -- Yosemite and later
use framework "Foundation"
use scripting additions
try
tell application "System Events"
tell application process "Microsoft Excel"
tell (first window whose subrole is "AXStandardWindow")
set fileURL to value of attribute "AXDocument"
end tell
end tell
end tell
set posixPathOfFrontExcelDocument to (current application's class "NSURL"'s URLWithString:fileURL)'s |path|() as text
set the clipboard to posixPathOfFrontExcelDocument
on error e number n
set e to e & return & return & "Num: " & n
if n ≠ -128 then
try
tell application (path to frontmost application as text) to set ddButton to button returned of ¬
(display dialog e with title "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
default button "OK" giving up after 30)
if ddButton = "Copy Error Message" then set the clipboard to e
end try
end if
end try
----------------------------------------------------------------
Excel (2011) tiene su propio menú de script, por lo que usar AppleScripts con él es bastante fácil.
Me han dicho que los productos de Office 2016 ya no tienen menús de script.
Personalmente uso tanto FastScripts como Keyboard Maestro para superar tales limitaciones. Confino la mayoría de mis AppleScripts a FastScripts y uso Keyboard Maestro para muchas otras tareas de automatización.
-ccs