I'm trying to open iCloud in the current Finder window/tab. The below AppleScript works with any other folder.
How can I open iCloud in the current Finder window with AppleScript?
tell application "Finder"
reopen
activate
set p to "~/Library/Mobile Documents/"
set target of Finder window 1 to POSIX file p
end tell
The script doesn't work because the Finder is not able to expand the tilde in POSIX paths.
This is an alternative with a relative path.
set userLibraryFolder to path to library folder from user domain
tell application "Finder"
reopen
activate
set iCloudDriveFolder to folder "iCloud Drive" of folder "Mobile Documents" of userLibraryFolder
set target of Finder window 1 to iCloudDriveFolder
end tell
This isn't a complete answer because this won't open the iCloud folder in the current tab, but it does open the iCloud folder rather than the "Mobile Documents" folder:
tell application "System Events" to open folder "~/Library/Mobile Documents"
I'm not familiar with any method that will give you the best of both worlds. It seems that you either must settle for the "Mobile Documents" folder opening in the tab you want; or a new tab being created to open the folder you want.
This is easy.
Create an alias of the iCloud folder and place that on the local hard drive then use Apple Script to open the alias and that opens the iCloud folder:
set itemPath to "Macintosh HD:Users:username:folder:alias_name"
tell application "Finder"
set theItem to item itemPath
if (class of theItem) is folder then activate
open theItem
end tell
Related
I am looking to write an AppleScript to move every file in every folder to another folder.
Currently, this is what I have:
tell application "Finder"
move (get every file of every folder of folder "Source_Folder" of desktop) to folder "Destination_Folder" of desktop
end tell
But this throws an error saying: error "Finder got an error: Can’t get document file \"ALGE71FL.cpg\" of folder \"Destination_Folder\" of folder \"Desktop\" of folder \"THIS_USER\" of folder \"Users\" of startup disk." number -1728 from document file "ALGE71FL.cpg" of folder "Destination_Folder" of folder "Desktop" of folder "THIS_USER" of folder "Users" of startup disk
Where ALGE71FL.cpg is the first file of interest.
Any solutions to this?
If you are looking to move only the files in the folders and not the folders themselves. This following AppleScript code is one way to achieve your goal.
activate
set searchFolder to choose folder with prompt "Choose The Folder To Search"
activate
set destinationFolder to choose folder with prompt "Choose The Folder To Move Files To"
tell application "Finder"
set theFiles to (files of entire contents of searchFolder) as alias list
move theFiles to destinationFolder
end tell
Right now I am using this code:
open folder
and it seems like it can not find the folder.
Do I have to specify a folder?
Basically open does not open folders.
You have to open a folder via the Finder and specify an HFS string path, alias or Finder folder specifier:
tell application "Finder" to open (path to desktop)
or
tell application "Finder" to open home
or
tell application "Finder" to open folder "Applications" of startup disk
I'm trying to launch a Finder window of a folder that's in the same directory as my script. When I run the code below, it launches a blank Finder window set to the path of the script not to the folder.
tell application "Finder"
tell application "Finder" to make new Finder window
set file_path to (path to me) as text
set target of Finder window 1 to file_path
end tell
How can I get the path to the folder of the script, not the script?
You were close. You do not need the text version of the file, you only need the file itself, then you can ask Finder for that file's container:
tell application "Finder"
tell application "Finder" to make new Finder window
set file_path to (path to me)
set target of Finder window 1 to file_path's container
end tell
The shortest way I know to do this is:
tell application "Finder" to open ((path to me as text) & "::")
Editing your script renders the following:
tell application "Finder"
make new Finder window -- There is no need for an your second tell statement
set file_path to (path to me as text) & "::" -- Goes up one directory
set target of Finder window 1 to file_path
end tell
I've some problems to find the correct apple script command: I want to open the info window for a given file or folder. It's that window which I can open via cmd+i in Finder. Now I want to be able to automate this action by script file.
My code actually looks like this:
set aFile to POSIX file "/Users/xyz/Documents/test.rtf"
tell application "Finder" to open information window of aFile
But that doesn't work. The error message says that the file "information window of Macintosh HD:Users:xyz:Documents:test.rtf" cannot opened.
Some commands are picky with posix file. So we can coerce that to something else and it will work...
set aFile to (POSIX file "/Users/xyz/Documents/test.rtf") as alias
tell application "Finder" to open information window of aFile
or
set aFile to (POSIX file "/Users/xyz/Documents/test.rtf") as text
tell application "Finder" to open information window of file aFile
I know tell application "Finder" to open POSIX file "/folder/path/" will open a new finder window, how can I open a folder in the current finder window?
I found the answer myself:
tell application "Finder"
set the target of the front Finder window to (POSIX file "/folder/path/")
end tell