Having a bit of trouble getting the following script to function. I have tried several different iterations:
tell application “Finder”
activate
open folder “today” of folder “downloads” of home
make finder folders open in new tabs
open folder “tomorrow” of folder “downloads” of home
end tell
I am familiar with the command “tell application “System Events” to keystroke “t” using command down”, but I have been told that that is for earlier releases of AppleScript years ago. I have opened the Finder with a tab and run the following which shows that my Finder now understands tabs, so I know it must be my code:
tell application “Finder”
properties of Finder window 1 <— also with “2”
end tell
tell application "Finder"
activate
set foldersOpenInTabsState to folders open in new tabs of Finder preferences
set foldersOpenInWindowsState to folders open in new windows of Finder preferences
set homeDirectory to home as text
set todayFolder to homeDirectory & "Downloads:today:"
set tomorrowFolder to homeDirectory & "Downloads:tomorrow:"
set folders open in new tabs of Finder preferences to true
set folders open in new windows of Finder preferences to false
open folder todayFolder
open folder tomorrowFolder
set folders open in new tabs of Finder preferences to foldersOpenInTabsState
set folders open in new windows of Finder preferences to foldersOpenInWindowsState
end tell
--all that should work, but doesn't so...
tell application "System Events"
tell process "Finder"
set its frontmost to true
click menu item "Merge all windows" of menu "Window" of menu bar 1
end tell
end tell
Also, I’m more in the habit of using the “path to” scripting addition rather than finder’s Home, but it works fine.
The problem with this approach is it will merge all open finder windows into tabs, not just those two, which may not be what you want.
You could close all open finder windows first, but that may not be what you want either.
You could get the properties ever every window first, close them, open and merge, then reopen open all the windows you closed. I can’t think of any other way to acheive the desired effect, which is a window with two tabs
My apologies for the delay in writing back, my open-heart surgery has prevented me from using the computer too frequently… but I do appreciate the information… again thanx.
However, in looking back, I was probably not clear concerning my endeavors. While the script opens the two directories, it does so in separate windows. What I want is to open the two directories in tabs within the same single window.
I have yet to analyze the script that was provided. I will do so and see if I can get two (or more) directories open in a single window using the tab functionality.
I too have found that “folders open in new tabs” doesn’t seem to work no matter how I enter the command…
Oh well…
So I incorporated the “fix” suggested by estockly. Here is my new script:
tell application “Finder”
activate
open folder “Tomorrow” of folder “Downloads” of home
open folder “Today” of folder “Downloads” of home
end tell
tell application “System Events”
tell process “Finder”
set its frontmost to true
click menu item “Merge all windows” of menu “Window” of menu bar 1
end tell
end tell
This works well and I can live with it. However, I have found one small glitch. If the script is run with Finder closed, it works perfectly. However, if Finder happens to be open at the time the script is run, it ends up with more tabs in the Finder window than desired. Like I said, I can live with it, but for the sake of learning (which I am) how can I always insure that Finder only opens these two specified directories with no additional tabs?
Not unexpected. There may be better ways to do this, but this is how I would do it…
tell application "Finder"
activate
set windowsToReopen to {}
set allMyWindows to every Finder window
repeat with thisWindow in allMyWindows
set windowProps to properties of thisWindow
set theTarget to target of windowProps as alias
set theBounds to bounds of windowProps
set theName to the name of windowProps
if theName is not in {"Tomorrow", "Today"} then
set the end of windowsToReopen to {theTarget, theBounds}
end if
close thisWindow
end repeat
open folder "Tomorrow" of folder "Downloads" of home
open folder "Today" of folder "Downloads" of home
my MergeTheWindows()
repeat with thisWindow in windowsToReopen
set {theTarget, theBounds} to thisWindow
set newWindow to make new Finder window at beginning
set the bounds of newWindow to theBounds
set the target of newWindow to theTarget
end repeat
end tell
on MergeTheWindows()
tell application "System Events"
tell process "Finder"
set its frontmost to true
click menu item "Merge all windows" of menu "Window" of menu bar 1
end tell
end tell
end MergeTheWindows
FYI, when you post scripts here, select the entire script your posting and click on AppleScript button and it will format nicely!