If you have the very useful utility Default Folder you can pull even more tricks than you think.
These are all my AppleScript handlers for Default Folder. They should all be up-to-date for Default Folder X 5.2.2.
I'm not going to bother to explain them – they should be pretty obvious to anyone who has some familiarity with AppleScript – but I will answer questions.
-Chris
EDIT: 2018/05/12 00:07 CDT
+ Added a handler to return the currently selected item in an Open or Save Dialog.
----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2018/03/14 22:18
# dMod: 2018/05/12 00:06
# Appl: Default Folder X
# Task: Working with Default Folder
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Default_Folder_X, @Handlers
----------------------------------------------------------------
--» Default Folder Handlers
----------------------------------------------------------------
--» defaultFolder_DialogIsOpen()
----------------------------------------------------------------
on defaultFolder_DialogIsOpen()
tell application "Default Folder X"
if (IsDialogOpen) = true then
return true
else
return false
end if
end tell
end defaultFolder_DialogIsOpen
----------------------------------------------------------------
--» defaultFolder_SwitchToFolder()
----------------------------------------------------------------
on defaultFolder_SwitchToFolder(folderAlias)
tell application "Default Folder X"
SwitchToFolder folderAlias
end tell
end defaultFolder_SwitchToFolder
----------------------------------------------------------------
--» getDefaultFolderCurrentFolder()
----------------------------------------------------------------
on getDefaultFolderCurrentFolder()
tell application "Default Folder X"
return (get GetCurrentFolder)
end tell
end getDefaultFolderCurrentFolder
----------------------------------------------------------------
--» getDefaultFolderSaveName()
----------------------------------------------------------------
on getDefaultFolderSaveName()
tell application "Default Folder X"
return (get GetSaveName)
end tell
end getDefaultFolderSaveName
----------------------------------------------------------------
--» setDefaultFolderSaveName()
----------------------------------------------------------------
on setDefaultFolderSaveName(newSaveName)
tell application "Default Folder X"
SetSaveName newSaveName
end tell
end setDefaultFolderSaveName
----------------------------------------------------------------
--» defaultfolder_GetCurrentSelection()
----------------------------------------------------------------
-- Get the currenly selected item in an Open or Save dialog.
----------------------------------------------------------------
on defaultfolder_GetCurrentSelection()
tell application "Default Folder X"
if IsDialogOpen then
set resultFile to GetCurrentSelection
else
error "Dialog is NOT open!"
end if
end tell
end defaultfolder_GetCurrentSelection
----------------------------------------------------------------
I am trying to implement one that gets the precise file selected - I see you use ":" instead of "/" for directory paths - is that a difference in how they are expressed in Default Folder X versus the Finder?
Anyway, I can get to the folder, but it won't select the file.
The goal is to select the actual file from that specific folder. I have multiple versions of same-named files in other places, but the files from this folder are the ones optimized for web. The script I have built will insert a token (or "global" in AppleScript-speak) via setting that token to the system clipboard before the AppleScript for the selection of the file gets called by KM. I assume that's the best way to pass something from KM to AS; I may be wrong. Anyhow, I'm hoping there's a way to articulate the full path to the one file under consideration, have it chosen, and then the rest I've got down pat. Then I can loop this X number of times and have the KM script upload these images unattended.
As far as getting or setting, I admit being sloppy in articulating that. It's probably just that I'm not as experienced in AS (haven't used it for a long time). I hope the explanation above also clarifies to you which word I should be using.
Safari itself. The browse button is in Safari, and the upload button is as well. It's the IN-BETWEEN task of selecting the precise file from the precise directory that I cannot master.
If I understand you correctly, all you need for your macro are the Actions to choose a specified file, correct?
AFAIK, this can't be done using Default Folder X. I don't see any commands to choose a file while in the open dialog. There is a command, SetSavedName and SwitchToFolder that will work for SAVING files, but none for choosing files.
So, here is a solution, somewhat of a kludge, that uses the standard macOS shortcut ⌘⇧G to go to a location (folder), and then a KM Insert by Typing to select the file in that folder to choose. I'd think there is a better way, but I don't see it.
You will need to adapt this for your needs, and insert the Actions into your current Macro.
Please let us know if this works for you and if you have questions, issues, and/or suggestions.
MACRO: Using Finder Go To Location Shortcut in File Open Dialog