hi
I new to Apple Script and i was using this script to open the pdf file.
--set the name of the file to open
property fileName : "epi27g04 .pdf"
--get the path to the containing folder
set myPath to (path to me as string)
set AppleScript's text item delimiters to ":"
set the parentFolder to ¬
((text items 1 thru -2 of myPath) & "") as string
set AppleScript's text item delimiters to ""
-- find the flash file
try
set targetFile to alias (the parentFolder & fileName)
on error
--ie if there's no file here by this name, it will quit.
return quit
end try
tell application "Finder"
open file targetFile
end tell
this script works well. But now my pdf file has long path and I don’t know how to put path in this script, so please help me.
I know there are some easy script to open the pdf file, but I like this script because it is not giving me any error message, if the pdf file is not found.
try
tell application "Finder"
open file "epi27g03.pdf"
end tell
on error
--ie if there's no file here by this name, it will quit.
return quit
end try
it works when the file is in same folder but when i attach path, it don’t
here is code
try
tell application "Finder"
open file "macintosh HD:User:Fun:desktop:test2:epi27g03.pdf"
end tell
on error
--ie if there's no file here by this name, it will quit.
return quit
end try
I don’t notice anything obviously wrong so I wonder if your path is correct. You can run the following snippet to get the path. When the dialog opens, navigate to and then select the pdf file. The path will be placed on the clipboard so that you can paste it into script editor.
set the clipboard to (choose file with prompt "Select the pdf file named "epi27g03.pdf" to have the path placed on the clipboard.") as text
thanks Rob
you have help me many times and you were right there was a path problem
BUT NOW I HAVE NEW PROBLEM
I want to target the parent folder in the above script
I think I should be more clear.
here is my path
open file "macintosh HD:User:Fun:desktop:test2:epi27g03.pdf"
Actualy my pdf file is in the parent folder of my script. So I am wondering if there is any way to target the parent folder and remove the long path name.
something like html code to target the parent folder
Assuming that I understand what you want to do, if you save your script as an application, this should work. Note that this will likely fail if you run the script from Script Editor. It should work fine when the script (application) is launched like any other application.
tell application "Finder"
set myFolder to (container of (path to me))
open file "epi27g03.pdf" of myFolder
end tell
thanks rob for concern in my problem
but that doesn’t work for me .
it opens the file only when the script and pdf are in the same folder.
but my pdf is in diferent folder.
here is the path to my script
Macintosh HD:Aplications:showroom:fscommand
my script is in fscommand folder
Now here is the path to my pdf
Macintosh HD:Aplications:showroom:acrobat:steelcace:executive
my pdf is in executive folder.
now you see that the folder showroom has got two folder 1 fscommand and 2 acrobat
script is in fscommand folder
and
pdf is in acrobate:steelcase:executive folder.
I’m not sure what you’re looking for either, but I thought I’d take a stab at it.
tell application “Finder”
set fileFolder to ((container of (container of (path to me))) as text) & “acrobat:steelcace:executive:”
open file “epi27g03.pdf” of folder fileFolder
end tell
you are very close to my answer I worked on your script and tried to change it according to my need. But I could not.
let me explain
When I run your script it tried to look for the folder - acrobat:steelcace:executive:
with in the same folder where my script is running from.
this may be because of the code - ((container of (container of (path to me)))
But my target folder ( acrobat:steelcace:executive:) is out the folder of my script.
let me explain very clearly -
I have folder name 'flash"
the folder “flash” has got two folder
1-fscommand
2- pdf
"fscommand " is the folder from where my script is running.
“pdf” is the folder where all my pdf document is stored
notice that “pdf” folder is out side the “fscommand”
and your script is looking for the “pdf” folder inside the “fscommand” folder.
hope you guys understand otherwise I have to give up
tell application "Finder"
set myFolder to (container of (container of (path to me))) as text
open file "epi27g03.pdf" of folder (myFolder & "pdf:")
end tell
If there is only one pdf file in the pdf folder, the following might work:
tell application "Finder"
set myFolder to (container of (container of (path to me))) as text
open (first file of folder (myFolder & "pdf:") whose name ends with ".pdf")
end tell
This would allow the script to work without knowing the name of the pdf file.
– Rob