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
Related
this is the script I'm trying to use:
on open thisItem
set this_folder to (the POSIX path of thisItem)
set export_folder to "Macintosh HD:Users:j****.*******:Desktop:AUTOMATOR:export"
set pdf_folder to "Macintosh HD:Users:j****.*****:Desktop:AUTOMATOR:PDF"
tell application "Adobe Illustrator" to open thisItem
tell application "Adobe Illustrator" to save current document in export_folder as pdf with options {class:PDF save options, PDF preset:"Low res proofing"}
tell application "Adobe Illustrator" to close current document
tell application "UltraLowPDF" to open
tell application "Finder" to move every file of folder "Macintosh HD:Users:j*****.*****:Desktop:AUTOMATOR:PDF" to container of this_folder
end open
This script should do a few things:
1. It creates a pdf file from an .ai file using adobe illustrator.
2. It then runs that pdf file through an automator workflow, which then spits out a pdf into a folder on my desktop.
3. It then moves that pdf file from the desktop, back to the folder of the original .ai file.
Every part of the script works fine except for step 3, it just seems to ignore it entirely. I've tried adding a delay, thinking the script was getting ahead of itself.
I've also tried isolating the move part of the script, using this droplet:
on open thisItem
set this_folder to (the POSIX path of thisItem)
tell application "Finder" to move every file of folder "Macintosh HD:Users:j****.******:Desktop:AUTOMATOR:PDF" to container of this_folder
end open
But this just throws up an error saying that it can't get the «class ctnr» of the file dropped on it (-1728).
Any help is greatly appreciated.
Thanks.
(note: I've starred out the user name part of the filepath for privacy)
EDIT: It seems that it's the Automator part of the script that is the problem, (the ''UltralowPDF"" app). After this runs, nothing after it in the script will run.
The problem is that thisItem is actually theseItems (aka a list). Either you need a repeat loop or – as in the following code – get the first item of the list.
The Finder does not accept (slash separated) POSIX paths. It works only with (colon separated) HFS paths.
The script uses the relative path path to desktop which point always to the desktop of the current user.
on open theseItems
set automatorFolder to (path to desktop as text) & "AUTOMATOR:"
set thisItem to item 1 of theseItems
set export_folder to automatorFolder & "export:"
set pdf_folder to automatorFolder & "PDF:"
tell application "Adobe Illustrator" to open thisItem
tell application "Adobe Illustrator" to save current document in export_folder as pdf with options {class:PDF save options, PDF preset:"Low res proofing"}
tell application "Adobe Illustrator" to close current document
tell application "UltraLowPDF" to open
tell application "Finder" to move every file of folder pdf_folder to container of thisItem
end open
There's a question on the site about getting file information via script, well answered by regulus6633. The solution provided worked for me on a folder, but I was unable to get it to work similarly on an application file.
set aFile to (POSIX file "/Applications/Google Chrome.app") as text
tell application "Finder" to open information window of application aFile
The path is correct, insofar as I can tell, but it keeps returning the syntax error:
"Finder got an error: Can’t get application "Macintosh HD:Applications:Google Chrome.app".
(I'm a designer, not a coder, so please excuse if the answer's obvious!)
You almost had it right, but "almost" can be frustrating in AppleScript :-)
set aFile to (POSIX file "/Applications/Google Chrome.app") as alias
tell application "Finder" to open information window of aFile
To get the data, rather than opening the window to look at, use
set aFile to (POSIX file "/Applications/Google Chrome.app") as alias
info for aFile
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 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
How does one open a file in the same folder as the AppleScript code? Something along these lines?
tell application "QuickTime Player"
activate
open "file.avi"
end tell
(which doesn't work).
Thanks!
tell application "Finder"
open file "somefile.txt" of folder of (file (path to me))
end tell
(only works once you've saved the script - otherwise "path to me" goes to the script editor)