Open a folder in the finder.

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Phiasco
Posts: 9
Joined: Tue May 10, 2011 10:59 pm

Open a folder in the finder.

Post by Phiasco » Fri Dec 09, 2011 8:48 pm

I have tried every method from every post I can find to get a a folder to open in the finder. I have tried -- put shell("open " & completePath ) and 10 variations on the syntax. I have tried many different ways of using apple script. Here is one sample

Code: Select all

   put  "" into field "dealList"
   put "tell application " & QUOTE & "Finder" & QUOTE into line 1 of field "dealList" 
   put "activate" into line 2 of field "dealList"
   put "set aPath to " & QUOTE & completePath & QUOTE & " as string" into line 3 of field "dealList"
   put "open folder aPath" into line 4 of field "dealList"
   put "end tell" into line 5 of field "dealList"
   do field "dealList" as "appleScript"
field "dealList" now looks like this, but fails to open the folder.

tell application "Finder"
activate
set aPath to "RTN-2012:0212-RTN:RTN-022712:PNJ-022712:PNJ21012:" as string
open folder aPath
end tell


When I copy the content of field "dealList" and paste it into the apple script editor (or onto this form) carriage returns are added and it fails to compile. (see below)


tell application "Finder"
activate
set aPath to "RTN-2012:0212-RTN:RTN-022712
:PNJ-022712
:PNJ21012:" as string
open folder aPath
end tell


I remove the extra new lines to cause the text to appear as it does in field "dealList". It compiles fine and opens the folder as expected.

The errors I am getting when using the shell lead me to believe that LiveCode is breaking the path variable (line of text) when sending it to the shell just as it is when sending it to applescript. I have also tried running the apple script from the command line, which produces the same failure.

Any ideas?

Thanks in advance.

Robert Short

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Open a folder in the finder.

Post by mwieder » Fri Dec 09, 2011 10:02 pm

Robert-

What's in completePath? How is it being generated?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3975
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Open a folder in the finder.

Post by bn » Fri Dec 09, 2011 10:13 pm

Robert,

actually your script works except that your path is incomplete. You have to start from the Harddisk an than on.

sometthing like this:
"Macintosh HD:Users:aUSER:Documents:Revolution test stacks:utilities:RunRevForum:Robert Short:"

if you pass it the complete path it works

Kind regards

Bernd

Phiasco
Posts: 9
Joined: Tue May 10, 2011 10:59 pm

Re: Open a folder in the finder.

Post by Phiasco » Sat Dec 10, 2011 1:50 am

Hello Bernd,

Thanks for the reply. The name of the drive is "RTN-2012" which is a network volume. I have many apple scripts using the same and similar paths. This path works fine when run from the Applescript editor, it only has an issue when run from LiveCode using Applescript, the shell or osa from shell passing the commands as arguments. Other scripts that I pass are working fine, but for some reason, LiveCode is inserting new lines into this path "RTN-2012:0212-RTN:RTN-022712:PNJ-022712:PNJ21012:". I have altered the Applescript to :

Code: Select all

   put  "" into field "dealList"
   put "tell application " & QUOTE & "Finder" & QUOTE into line 1 of field "dealList" --& CR & tab & 
   put "activate" into line 2 of field "dealList" --& CR & tab & 
   put "set aPath to " & QUOTE & completePath & QUOTE & " as string" into line 3 of field "dealList"
   [b]put "display dialog aPath" into line 4 of field "dealList"[/b]          <<<<<<<<<<----------------- Change inserted here
   --put "open folder aPath" into line 4 of field "dealList" --& CR & 
   put "end tell" into line 5 of field "dealList"
   do field "dealList" as "appleScript"
This returns

RTN-2012:0212-RTN:RTN-022712
:PNJ-022712
:PNJ21012:

in a dialog box. This does not look like a word wrap problem because there is plenty of space on line two for the entirety of line three.


Hi mwieder,

Here is the code I am using to build the path. For this function I am pulling a 6 character start date from an AS400 database. The dealNumber is supplied by the user.

Code: Select all

   put "" into completePath --put "/Volumes/" into completePath
   put ":" into pathDelimiter
   
   put char 1 to 3 of word 1 of field "dealNumber" into pathRegion
   put char 1 to 8 of word 1 of field "dealNumber" into pathDealNumber
   
   put URL ("xxtp://xxxxx.markettechmedia.xom/CustomerData.aspx?dealNumber="  & field dealNumber) into dealData
   set the itemDelimiter to "|"
   put last item of line 1 of dealData into startDate
   put char 1 to 2 of startDate & char 5 to 6 of startDate into mmyyStartDate
   put "-20" & char 5 to 6 of startDate into yyyyStartDate
   
   if char 1 of word 1 of field "dealNumber" is "P" then
      put "RTN" into theProductType
   else if char 1 of word 1 of field "dealNumber" is "A" then
      put "ADCART" into theProductType
   end if

   if theProductType is "RTN" then
      put completePath & theProductType & yyyyStartDate & pathDelimiter & mmyyStartDate & "-" & theProductType & pathDelimiter & theProductType & "-" & startDate into completePath
      put completePath & pathDelimiter & pathRegion & "-" & startDate & pathDelimiter & pathDealNumber & pathDelimiter into completePath
  end if
The logic is sound because I can open files within the folder from within LiveCode, just not the folder itself.


And I would love to know if there is another method for opening the folder in the Finder or Explorer so that I do not need to use a script at all.

Thanks for the reply's. I am excited about some of the things I will be able to do with LiveCode, just have to get over the learning hump.

Robert

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Open a folder in the finder.

Post by Klaus » Sat Dec 10, 2011 11:40 am

Hi guys,

well:
...
launch document "complete path/to the folder/you want/to open/here"
...
will do the job, at least it does here on my Mac :D
Just tested with LC 4.6.3!


Best

Klaus

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3975
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Open a folder in the finder.

Post by bn » Sat Dec 10, 2011 1:51 pm

Hi Klaus,

Code: Select all

launch document "complete path/to the folder/you want/to open/here"
to open a folder

now that is smart!

Who would have thought of that? Thank you.

Kind regards

Bernd

Phiasco
Posts: 9
Joined: Tue May 10, 2011 10:59 pm

Re: Open a folder in the finder.

Post by Phiasco » Mon Dec 12, 2011 8:41 am

Hi Klaus,

I have tried that and thought it was not an option because it also does not work on a constructed path. For example, if I use

Code: Select all

put "/Volumes/RTN-2012/0212-RTN/RTN-022712/PNJ-022712/PNJ21012" into completePath
launch document completePath
it will work for every path I hard code. (I had not put a pre-constructed path in for testing which I should have done before now, thanks you for bring that to my attention)
However, when building the same exact path from other variables,

Code: Select all

put completePath & theProductType & yyyyStartDate & pathDelimiter & mmyyStartDate & "-" & theProductType & pathDelimiter & theProductType & "-" & startDate & pathDelimiter & pathRegion & "-" & startDate & pathDelimiter & pathDealNumber into completePath
launch document completePath
it does not work.

I think what I will need to do is build out this portion of the application in Applescript and launch the script to build the path and open the folder. Kinda messy, but this has taken up a lot of time. I have used this same code to open many files and do not have the same troubles. The trouble is only when referencing folders. I wonder why?

Thank you for your input.

Robert

kdjanz
Posts: 300
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: Open a folder in the finder.

Post by kdjanz » Fri Jan 13, 2012 8:30 am

Silly newbie question, but is your path delimiter set correctly? Does your assembled completePath variable look correct if you put it into the message box before launching?

Kelly

Phiasco
Posts: 9
Joined: Tue May 10, 2011 10:59 pm

Re: Open a folder in the finder.

Post by Phiasco » Fri Jan 13, 2012 6:01 pm

Hi Kelly, Yep and Yep. And it is a paths where I have built the entire folder structure using the same language. Additionally, I can open a file within the folder using the same coding structure. Just can't get that darn folder to open in the Finder. I do have some ideas in my head to try at a later time. My energies are going to other areas of this project right now. I will post a resolution if I find one when I get some time to try my ideas.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Open a folder in the finder.

Post by mwieder » Fri Jan 13, 2012 6:30 pm

Robert-

If your hardcoded example is the actual path then your second code example is missing a "-" character.

Code: Select all

put completePath & theProductType & "-" & yyyyStartDate & pathDelimiter & mmyyStartDate & "-" & theProductType & pathDelimiter & theProductType & "-" & startDate & pathDelimiter & pathRegion & "-" & startDate & pathDelimiter & pathDealNumber into completePath

Phiasco
Posts: 9
Joined: Tue May 10, 2011 10:59 pm

Re: Open a folder in the finder.

Post by Phiasco » Fri Jan 13, 2012 11:26 pm

So close, I went back to take a look and I had put the hyphen in the "yyyyStartDate". I really thought that might be it because most problems usually have a simple solution like that. Now that my mind is working on this again, I am going to have to spend some time on it this weekend and test some of the thoughts I have had on working around this. I was thinking I would set the defaultFolder to one level up from the folder, then trying to launch from there.

Code: Select all

 
   put "-20" & char 5 to 6 of startDate into yyyyStartDate
   

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Open a folder in the finder.

Post by mwieder » Fri Jan 13, 2012 11:30 pm

You might want to try putting

Code: Select all

put completePath into msg
before your launch statement just to see what you've got in there.

Or put in a breakpoint and examine it in the debugger.

ramav
Posts: 20
Joined: Tue Jan 06, 2009 4:56 am

Re: Open a folder in the finder.

Post by ramav » Sat Jan 21, 2012 3:36 am

This is my humble contribution--I have had similar problems working with a variety of Oses when attempting to "shell" and use an absolute directory path reference. Very often, the path ref within quotes as a literal string works, but forming he reference using variables and literals concatenated does not work.
Thus, document "A literal path" works but document mypath (where mypath is formed from a medley of strings and variables) does not work. The solution is to embed extra quotes enclosing the medley by concatenating the ascii code for a double quote (I forgot what that is) on each side. sometimes even this does not work, so you may have to try single quote ascii equivalent. I had even more insidious problems shelling out of Excel (works perfectly as a front end to any program, one of the best kept secrets of excel!) on a Mac--I will try and look at my VBA code and tell you how it works if you are still interested. Unfortunately, this was a painful process and I forgot how I did it, have it documented somewhere...
best

On a different note, how come this age old problem/feature request to RunRev (see below) has been studiously ignored never been implemented and dismissed as a non-feature and why are having so many threads arguing about whether this feature is really needed, a true character wrap (not word wrap with spaces) in fields?
See original thread below and the reply! (This is unbelievable for a commercial product like LiveCode is supposed to be--I cannot debug anything on the Internet when i have long GET and POST requests that I need to store and look at in fields!!!)

--This was in 2002, and it still is today in 2012!!

Recently (2002!), Brent Neal wrote:
>
>>>> Is there something odd with wrapping in text fields in the OS X version?
>
>>> Does the text have spaces in it?
>
>> No. I just tapped at random keys (i.e. asdfasfdasdf). Consider
>> SimpleText. If you hold down a single key, when it reaches the text
>> field width, it starts over on the next line. That shouldn't matter.
>
>Unfortunately, wrapping lines of text in MC/REV requires that there be
>spaces among characters.

Fermin
Posts: 142
Joined: Fri Jun 05, 2015 10:44 pm

Re: Open a folder in the finder.

Post by Fermin » Wed Dec 02, 2020 11:08 pm

launch url ("file:" & thePath)

Jacque
http://forums.livecode.com/viewtopic.php?t=30676

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Open a folder in the finder.

Post by Klaus » Wed Dec 02, 2020 11:30 pm

Hola Fermin,

a BIT late for the party, right? :-)

I prefer:

Code: Select all

...
launch document "path/to/folder"
...
Works on Mac and Windows!


Best

Klaus

Post Reply

Return to “Mac OS”