Welcome to MacBoardz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Applescript to open a file

 
   Macintosh computer (Home) -> Apple Scripts RSS
Next:  startup script  
Author Message
dkletzing

External


Since: Nov 26, 2008
Posts: 6



(Msg. 1) Posted: Wed Nov 26, 2008 6:39 am
Post subject: Applescript to open a file
Archived from groups: alt>comp>lang>applescript (more info?)

Hello:

I'm trying to write a simple Applescript that will open a file in
second application. File 1 is already open in application 1. I want to
switch over to application 2 and open file 1 in application 2. My
problem is I need to build in something in the script for the path
pointing to file 1. I'm trying to reference the file path from
application 1 but don't know how to buid it into the script. Any ideas
would be much appreciated.

 >> Stay informed about: Applescript to open a file 
Back to top
Login to vote
dkletzing

External


Since: Nov 26, 2008
Posts: 6



(Msg. 2) Posted: Wed Nov 26, 2008 9:46 am
Post subject: Re: Applescript to open a file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Nov 26, 11:17 am, Jolly Roger wrote:
> In article
> ,
>
>  dkletz...@cfl.rr.com wrote:
> > I'm trying to write a simple Applescript that will open a file in
> > second application. File 1 is already open in application 1. I want to
> > switch over to application 2 and open file 1 in application 2. My
> > problem is I need to build in something in the script for the path
> > pointing to file 1. I'm trying to reference the file path from
> > application 1 but don't know how to buid it into the script. Any ideas
> > would be much appreciated.
>
> More details please.  What are the two applications you're referencing?
>
> Have you considered that you can right-click (or Control-click) a file
> in the Finder and choose Open With > (any app) to open the file in
> another application?
>
> Have you considered the implications of what happens if both
> applications attempt to write to the file at the same time?
>
> --
> Send responses to the relevant news group rather than email to me.
> E-mail sent to this address may be devoured by my very hungry SPAM
> filter. Due to Google's refusal to prevent spammers from posting
> messages through their servers, I often ignore posts from Google
> Groups. Use a real news client if you want me to see your posts.
>
> JR

The two applications are BBEdit 8.7 and Textures for OSX. I have a
file open in BBEdit and want to run a script which will save the
document then switch over and open Textures. In order for Textures to
typeset the document, Blue Sky has set things up so that the file must
also be open in Textures. It works fine if I do everything manually,
which is a pain. I'm just trying to write a script that do the work

 >> Stay informed about: Applescript to open a file 
Back to top
Login to vote
Jolly Roger

External


Since: Sep 09, 2006
Posts: 1943



(Msg. 3) Posted: Wed Nov 26, 2008 10:17 am
Post subject: Re: Applescript to open a file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article
,
dkletzing.DeleteThis@cfl.rr.com wrote:

> I'm trying to write a simple Applescript that will open a file in
> second application. File 1 is already open in application 1. I want to
> switch over to application 2 and open file 1 in application 2. My
> problem is I need to build in something in the script for the path
> pointing to file 1. I'm trying to reference the file path from
> application 1 but don't know how to buid it into the script. Any ideas
> would be much appreciated.

More details please. What are the two applications you're referencing?

Have you considered that you can right-click (or Control-click) a file
in the Finder and choose Open With > (any app) to open the file in
another application?

Have you considered the implications of what happens if both
applications attempt to write to the file at the same time?

--
Send responses to the relevant news group rather than email to me.
E-mail sent to this address may be devoured by my very hungry SPAM
filter. Due to Google's refusal to prevent spammers from posting
messages through their servers, I often ignore posts from Google
Groups. Use a real news client if you want me to see your posts.

JR
 >> Stay informed about: Applescript to open a file 
Back to top
Login to vote
dkletzing

External


Since: Nov 26, 2008
Posts: 6



(Msg. 4) Posted: Wed Nov 26, 2008 10:33 am
Post subject: Re: Applescript to open a file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Nov 26, 1:11 pm, Jolly Roger wrote:
> In article
> ,
>
>
>
>  dkletz...@cfl.rr.com wrote:
> > On Nov 26, 11:17 am, Jolly Roger wrote:
> > > In article
> > > ,
>
> > >  dkletz...@cfl.rr.com wrote:
> > > > I'm trying to write a simple Applescript that will open a file in
> > > > second application. File 1 is already open in application 1. I want to
> > > > switch over to application 2 and open file 1 in application 2. My
> > > > problem is I need to build in something in the script for the path
> > > > pointing to file 1. I'm trying to reference the file path from
> > > > application 1 but don't know how to buid it into the script. Any ideas
> > > > would be much appreciated.
>
> > > More details please.  What are the two applications you're referencing?
>
> > > Have you considered that you can right-click (or Control-click) a file
> > > in the Finder and choose Open With > (any app) to open the file in
> > > another application?
>
> > > Have you considered the implications of what happens if both
> > > applications attempt to write to the file at the same time?
>
> > The two applications are BBEdit 8.7 and Textures for OSX. I have a
> > file open in BBEdit and want to run a script which will save the
> > document then switch over and open Textures. In order for Textures to
> > typeset the document, Blue Sky has set things up so that the file must
> > also be open in Textures. It works fine if I do everything manually,
> > which is a pain. I'm just trying to write a script that do the work
>
> Definitely sounds easy to do in Applescript. So what have you tried so
> far? paste your script here and describe the problem you are having.
>
> --
> Send responses to the relevant news group rather than email to me.
> E-mail sent to this address may be devoured by my very hungry SPAM
> filter. Due to Google's refusal to prevent spammers from posting
> messages through their servers, I often ignore posts from Google
> Groups. Use a real news client if you want me to see your posts.
>
> JR

Here's the script that I managed to cobble together:

set current_name to name of window 1
tell application "BBEdit 6.0"
save text document current_name
end tell
tell application "Textures"
activate
open file current_name
end tell

This gets me over to Textures but it doesn't open the file that is
open in BBEdit. I suspect that current_name doesn't pick up the file
path, so Textures doesn't know what to do. That's the place I'm having
trouble with in the script. I don't know how to get the file path
included in the initial set and how to call it once over in Textures.
 >> Stay informed about: Applescript to open a file 
Back to top
Login to vote
dkletzing

External


Since: Nov 26, 2008
Posts: 6



(Msg. 5) Posted: Wed Nov 26, 2008 11:20 am
Post subject: Re: Applescript to open a file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Nov 26, 1:49 pm, Jolly Roger wrote:
> In article
> ,
>
>
>
>  dkletz...@cfl.rr.com wrote:
> > Here's the script that I managed to cobble together:
>
> > set current_name to name of window 1
> > tell application "BBEdit 6.0"
> >    save text document current_name
> > end tell
> > tell application "Textures"
> >    activate
> >    open file current_name
> > end tell
>
> > This gets me over to Textures but it doesn't open the file that is
> > open in BBEdit. I suspect that current_name doesn't pick up the file
> > path, so Textures doesn't know what to do. That's the place I'm having
> > trouble with in the script. I don't know how to get the file path
> > included in the initial set and how to call it once over in Textures.
>
> You're right. The window name is just a name - and it's not even
> guaranteed to be the name of the file in question.  So it's not a good
> idea to use window names for file system operations.
>
> Have you looked at the BBEdit dictionary to see if it will give you the
> path? You should always look at application dictionaries to find out
> what Applescript terminology a given application supports.
>
> To view an application's AppleScript dictionary:
>
> 1. Open Script Editor.
> 2. From the menu bar, choose File > Open Dictionary. A list of
> applications will appear.
> 3. Select the application name in the list.
> 4. Click OK.
>
> I don't have BBEdit; but I do have TextWrangler. In TextWrangler, if I
> click "BBEdit Suite", and then select the "document" class to the right
> of that, I see:
>
> ---
> document n [inh. item] : every open document
>
> ELEMENTS
> contained by application.
>
> PROPERTIES
> modified (boolean, r/o) : does this document have unsaved changes?
> modifiable (boolean, r/o) : can this document be modified?
> modification date (date, r/o) : date and time this document was last
> modified
> name (text) : the title of the window (r/o if on disk is true)
> on disk (boolean, r/o) : does this document exist on disk?
> file (alias, r/o) : the disk file containing the document¹s data
> creator type (type) : the OSType identifying the application that
> created the item
> window (window, r/o) : this document¹s window
> ---
>
> So each document has a property called "file" that is an alias of the
> file on disk. You'll find most often when you deal with files in
> Applescript, you're actually dealing with an alias to the file. Aliases
> are actually better than textual paths, because the operating system can
> find the target file even if it's been moved or renamed since the alias
> was obtained.
>
> So I think you want something more like this:
>
> -- begin script
> tell application "TextWrangler"
>      set fileAlias to the first document's file
>      save the first document
>      close the first document
> end tell
>
> tell application "Textures"
>      activate
>      open fileAlias
> end tell
> -- end script
>
> --
> Send responses to the relevant news group rather than email to me.
> E-mail sent to this address may be devoured by my very hungry SPAM
> filter. Due to Google's refusal to prevent spammers from posting
> messages through their servers, I often ignore posts from Google
> Groups. Use a real news client if you want me to see your posts.
>
> JR

I really appreciate your help with this. I think it's almost there.
This script does open the same document in Textures. But it closed the
source file back in BBEdit, so I deleted the line that says close the
first document. Now it leaves the file open in BBEdit. But something
isn't right. If I make some changes in the BBEdit source file, then
run the script, the file in Textures doesn't have the changes recorded
in it. It's still the original file without the changes. I tried
closing the file in Textures, went back to BBEdit, ran the script.
This time the source file opened in Textures and was updated with the
changes in it. It seems like the fileAlias doesn't get the newly saved
BBEdit document that has the changes in it?
 >> Stay informed about: Applescript to open a file 
Back to top
Login to vote
dkletzing

External


Since: Nov 26, 2008
Posts: 6



(Msg. 6) Posted: Wed Nov 26, 2008 11:50 am
Post subject: Re: Applescript to open a file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Nov 26, 2:26 pm, Jolly Roger wrote:
> In article
> ,
>
>
>
>  dkletz...@cfl.rr.com wrote:
> > On Nov 26, 1:49 pm, Jolly Roger wrote:
> > > I think you want something more like this:
>
> > > -- begin script
> > > tell application "TextWrangler"
> > >      set fileAlias to the first document's file
> > >      save the first document
> > >      close the first document
> > > end tell
>
> > > tell application "Textures"
> > >      activate
> > >      open fileAlias
> > > end tell
> > > -- end script
>
> > I really appreciate your help with this. I think it's almost there.
> > This script does open the same document in Textures. But it closed the
> > source file back in BBEdit, so I deleted the line that says close the
> > first document. Now it leaves the file open in BBEdit. But something
> > isn't right. If I make some changes in the BBEdit source file, then
> > run the script, the file in Textures doesn't have the changes recorded
> > in it. It's still the original file without the changes. I tried
> > closing the file in Textures, went back to BBEdit, ran the script.
> > This time the source file opened in Textures and was updated with the
> > changes in it. It seems like the fileAlias doesn't get the newly saved
> > BBEdit document that has the changes in it?
>
> That has nothing to do with the alias. That's just a pointer to the
> file. Textures simply isn't bothering to check to see if the file has
> changed since you first opened it in Textures. You will have to close
> the file in Textures every time you want to modify the file in BBEdit.
>
> And this is why I added the close command. Very often, application
> developers assume that once a file is open with their application, it
> will not be modified in some other application. In fact, if two
> applications attempt to modify the same file at the same time,
> corruption can result. So it's always a good idea not to open the same
> document in multiple applications at the same time unless you are
> absolutely sure you know how each application will handle it.
>
> --
> Send responses to the relevant news group rather than email to me.
> E-mail sent to this address may be devoured by my very hungry SPAM
> filter. Due to Google's refusal to prevent spammers from posting
> messages through their servers, I often ignore posts from Google
> Groups. Use a real news client if you want me to see your posts.
>
> JR

I see what you are saying. So I think I'm in a catch 22 situation
here. I go to the BBEdit source file, make some changes. Before I run
the script I want to save the changes, but as soon as I save, it
switches over to Textures and typeset the new document because that's
the way Blue Sky set up the interaction between the two programs. I
think I will just have to live with opening the file in Textures
manually until Blue Sky updates the way it handles the interaction
between these two applications. Thanks again for your help.
 >> Stay informed about: Applescript to open a file 
Back to top
Login to vote
Jolly Roger

External


Since: Sep 09, 2006
Posts: 1943



(Msg. 7) Posted: Wed Nov 26, 2008 12:11 pm
Post subject: Re: Applescript to open a file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article
,
dkletzing.DeleteThis@cfl.rr.com wrote:

> On Nov 26, 11:17 am, Jolly Roger wrote:
> > In article
> > ,
> >
> >  dkletz...@cfl.rr.com wrote:
> > > I'm trying to write a simple Applescript that will open a file in
> > > second application. File 1 is already open in application 1. I want to
> > > switch over to application 2 and open file 1 in application 2. My
> > > problem is I need to build in something in the script for the path
> > > pointing to file 1. I'm trying to reference the file path from
> > > application 1 but don't know how to buid it into the script. Any ideas
> > > would be much appreciated.
> >
> > More details please.  What are the two applications you're referencing?
> >
> > Have you considered that you can right-click (or Control-click) a file
> > in the Finder and choose Open With > (any app) to open the file in
> > another application?
> >
> > Have you considered the implications of what happens if both
> > applications attempt to write to the file at the same time?
>
> The two applications are BBEdit 8.7 and Textures for OSX. I have a
> file open in BBEdit and want to run a script which will save the
> document then switch over and open Textures. In order for Textures to
> typeset the document, Blue Sky has set things up so that the file must
> also be open in Textures. It works fine if I do everything manually,
> which is a pain. I'm just trying to write a script that do the work

Definitely sounds easy to do in Applescript. So what have you tried so
far? paste your script here and describe the problem you are having.

--
Send responses to the relevant news group rather than email to me.
E-mail sent to this address may be devoured by my very hungry SPAM
filter. Due to Google's refusal to prevent spammers from posting
messages through their servers, I often ignore posts from Google
Groups. Use a real news client if you want me to see your posts.

JR
 >> Stay informed about: Applescript to open a file 
Back to top
Login to vote
Jolly Roger

External


Since: Sep 09, 2006
Posts: 1943



(Msg. 8) Posted: Wed Nov 26, 2008 12:49 pm
Post subject: Re: Applescript to open a file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article
,
dkletzing.DeleteThis@cfl.rr.com wrote:

> Here's the script that I managed to cobble together:
>
> set current_name to name of window 1
> tell application "BBEdit 6.0"
> save text document current_name
> end tell
> tell application "Textures"
> activate
> open file current_name
> end tell
>
> This gets me over to Textures but it doesn't open the file that is
> open in BBEdit. I suspect that current_name doesn't pick up the file
> path, so Textures doesn't know what to do. That's the place I'm having
> trouble with in the script. I don't know how to get the file path
> included in the initial set and how to call it once over in Textures.

You're right. The window name is just a name - and it's not even
guaranteed to be the name of the file in question. So it's not a good
idea to use window names for file system operations.

Have you looked at the BBEdit dictionary to see if it will give you the
path? You should always look at application dictionaries to find out
what Applescript terminology a given application supports.

To view an application's AppleScript dictionary:

1. Open Script Editor.
2. From the menu bar, choose File > Open Dictionary. A list of
applications will appear.
3. Select the application name in the list.
4. Click OK.

I don't have BBEdit; but I do have TextWrangler. In TextWrangler, if I
click "BBEdit Suite", and then select the "document" class to the right
of that, I see:

---
document n [inh. item] : every open document

ELEMENTS
contained by application.

PROPERTIES
modified (boolean, r/o) : does this document have unsaved changes?
modifiable (boolean, r/o) : can this document be modified?
modification date (date, r/o) : date and time this document was last
modified
name (text) : the title of the window (r/o if on disk is true)
on disk (boolean, r/o) : does this document exist on disk?
file (alias, r/o) : the disk file containing the document¹s data
creator type (type) : the OSType identifying the application that
created the item
window (window, r/o) : this document¹s window
---

So each document has a property called "file" that is an alias of the
file on disk. You'll find most often when you deal with files in
Applescript, you're actually dealing with an alias to the file. Aliases
are actually better than textual paths, because the operating system can
find the target file even if it's been moved or renamed since the alias
was obtained.

So I think you want something more like this:

-- begin script
tell application "TextWrangler"
set fileAlias to the first document's file
save the first document
close the first document
end tell

tell application "Textures"
activate
open fileAlias
end tell
-- end script

--
Send responses to the relevant news group rather than email to me.
E-mail sent to this address may be devoured by my very hungry SPAM
filter. Due to Google's refusal to prevent spammers from posting
messages through their servers, I often ignore posts from Google
Groups. Use a real news client if you want me to see your posts.

JR
 >> Stay informed about: Applescript to open a file 
Back to top
Login to vote
Jolly Roger

External


Since: Sep 09, 2006
Posts: 1943



(Msg. 9) Posted: Wed Nov 26, 2008 1:26 pm
Post subject: Re: Applescript to open a file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article
,
dkletzing.RemoveThis@cfl.rr.com wrote:

> On Nov 26, 1:49 pm, Jolly Roger wrote:
> > I think you want something more like this:
> >
> > -- begin script
> > tell application "TextWrangler"
> >      set fileAlias to the first document's file
> >      save the first document
> >      close the first document
> > end tell
> >
> > tell application "Textures"
> >      activate
> >      open fileAlias
> > end tell
> > -- end script
>
> I really appreciate your help with this. I think it's almost there.
> This script does open the same document in Textures. But it closed the
> source file back in BBEdit, so I deleted the line that says close the
> first document. Now it leaves the file open in BBEdit. But something
> isn't right. If I make some changes in the BBEdit source file, then
> run the script, the file in Textures doesn't have the changes recorded
> in it. It's still the original file without the changes. I tried
> closing the file in Textures, went back to BBEdit, ran the script.
> This time the source file opened in Textures and was updated with the
> changes in it. It seems like the fileAlias doesn't get the newly saved
> BBEdit document that has the changes in it?

That has nothing to do with the alias. That's just a pointer to the
file. Textures simply isn't bothering to check to see if the file has
changed since you first opened it in Textures. You will have to close
the file in Textures every time you want to modify the file in BBEdit.

And this is why I added the close command. Very often, application
developers assume that once a file is open with their application, it
will not be modified in some other application. In fact, if two
applications attempt to modify the same file at the same time,
corruption can result. So it's always a good idea not to open the same
document in multiple applications at the same time unless you are
absolutely sure you know how each application will handle it.

--
Send responses to the relevant news group rather than email to me.
E-mail sent to this address may be devoured by my very hungry SPAM
filter. Due to Google's refusal to prevent spammers from posting
messages through their servers, I often ignore posts from Google
Groups. Use a real news client if you want me to see your posts.

JR
 >> Stay informed about: Applescript to open a file 
Back to top
Login to vote
dkletzing

External


Since: Nov 26, 2008
Posts: 6



(Msg. 10) Posted: Wed Nov 26, 2008 1:28 pm
Post subject: Re: Applescript to open a file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Nov 26, 3:36 pm, Michelle Steiner wrote:
> In article
> ,
>
>  dkletz...@cfl.rr.com wrote:
> > I see what you are saying. So I think I'm in a catch 22 situation
> > here. I go to the BBEdit source file, make some changes. Before I run
> > the script I want to save the changes, but as soon as I save, it
> > switches over to Textures and typeset the new document because that's
> > the way Blue Sky set up the interaction between the two programs. I
> > think I will just have to live with opening the file in Textures
> > manually until Blue Sky updates the way it handles the interaction
> > between these two applications. Thanks again for your help.
>
> Why not just wait until you finish editing the text file before opening
> it in Textures?  Or if you want to continue with a script, script
> textures to close the file, then have the script save it with BBEdit,
> and then reopen it with Textures.
>
> --
> It's now time for healing, and for fixing the damage the GOP did to America.

When I make editing changes in a source file, I need to see how the
typeset page comes out before I go on to make further changes. In
other words I really need a dynamic interaction between source and
typeset window. I have this now but it's all in Classic mode. There is
a plug-in for BBEdit in Classic mode that works beautifully and
provides this type of link. But in OS X there is no such plug-in. At
some point I will have to move up to Leopard from Tiger and will no
longer have Classic mode to operate in. Blue Sky has linked BBEdit
with Textures. I'm just trying to make it a bit less cumbersome to
use. If I tell Textures to close the file, then the typeset preview
window also closes and I can't see the results of the typesetting. I
think I just have to wait until Blue Sky finishes developing their OS
X version of Textures. At this point it's still beta.
 >> Stay informed about: Applescript to open a file 
Back to top
Login to vote
Michelle Steiner

External


Since: Jul 15, 2003
Posts: 3627



(Msg. 11) Posted: Wed Nov 26, 2008 1:36 pm
Post subject: Re: Applescript to open a file [Login to view extended thread Info.]
Imported from groups: per prev. post (more info?)

Back to top
Login to vote
Display posts from previous:   
Related Topics:
AppleScript Language Guide for AppleScript 2.0 - Hello, The AppleScript Language Guide, updated for AppleScript 2.0, is now available here : <http://developer.apple.com/documentation/AppleScript/ Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html> Patrick -- Patrick Stadelmann..

Applescript RSS - Is there any way to acquire an RSS feed using Applescript? I'd like to be able to specify the RSS URL, then have Applescript consume the most recent 5 entries. Thanks, A

Open a file in PhotoshopCS - I would open an image with photoshop and do some action. I try this 2 scripts: set the topLevelFolder to (choose folder) as string tell application "Finder" set fileList to name of every file of folder topLevelFolder as list end tell ...

New AppleScript features in 10.5 - On this page <http://www.apple.com/applescript/> (which is formatted in a very un-Apple manner) there's a list of the new features in AppleScript, with each on a clickable link. Some look interesting and I don't want to torpedo any fun discussio...

Leopard, Firefox & Applescript - Can anyone tell me why a script I wrote to log in to my bank no longer works in Firefox since I installed Leopard? Can it by fixed? Thanks
   Macintosh computer (Home) -> Apple Scripts All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]