Wednesday, November 22, 2017

#1 2010-08-03 06:55:30 am

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Show differences in two AppleScript files with TextWrangler

Hello.

The script displays differences of two AppleScript Files which is selected in Finder in TextWrangler (free), and gives you a nice display of the differences, though colorless.

I think the script only works in SL, or with Leopard if that was when osadecompile was introduced. I will come back and add support for Tiger, through Satimage.

So this is isn't quite finished, but it is still in such a state that it should prove useful for many. You have to have TextWrangler (which is free) installed in order to use this. -And the command line tools! TextWrangler can be  downloaded from here

Edit You don't really need this if you have Smile in the first place since you can compare two windows in it.

Applescript:




-- The Idea and implementation and any faults is totally mine. © McUsr 2010 and put in the Public Domain.
-- The usually guarrantees about nothing what so ever applies, use it at your own risk.
-- Read the documentation.
-- You are not allowed to post this code elsewhere, but may of course refer to the post at macscripter.net.
-- macscripter.net/viewtopic.php?id=33758
(*
TERMS OF USE.
This applies only to posting code, as long as you don't post it on other websites, or displays it (the code) on your own, you are welcome to do
whatever you want to do with it without any further permission.
Except for the following: Selling the code as is, or removing copyright statmentents and the embedded link in the code (without the http:// part) from the code.
I don't require you to keep this whole novel, but you must keep the link which refers to where it was originally posted. And my copyright.
You must also state what you eventually have done with the original source. This obviously doesn't matter if you distribute AppleScript as read only. I do not require you to embed any properties helding copyright notice for the code when you distribute as read only.

Credit for having contributed to your product would in all cases be nice!

If you use this code as part of script of yours you are of course welcome to post that code with my code in it here at macscripter.net. If you then wish to post your code elsewhere after having uploaded it to MacScripter.net please email me and ask for permission.

The ideal situation is however that you then refer to your code by a link to MacScripter.net
The sole reason for this, is that it is so much better for all of us to have a centralized codebase which are updated, than having to roam the net to find any usable snippets. Which some of us probabaly originated in the first hand.

I'm picky about this. If I find you to have published parts of my code on any other site without previous permission, I'll do what I can to have the site remove the code, ban you, and sue you under the jurisdiction of AGDER LAGMANNSRETT of Norway. Those are the terms you silently agree too by using this code.

The above paragraphs are also valid if you violate any of my terms.

If you use this or have advantage of this code in a professional setting, where professional setting means that you use this code to earn money by keeping yourself more productive. Or if you as an employee share the resulting script with other coworkers, enhancing the productivity of your company, then a modest donation to MacScripter.net would be appreciated.

*)

-- © McUsr 2010 and put in Public Domain see: macscripter.net/viewtopic.php?id=33758 for reference and terms of use.

on run
   -- check if text wrangler of bbedit is installed.
   -- Dette er blokka for at finder er oppe.
   tell application "Finder"
       activate
       set theSel to (get selection)
       
       set selCount to count theSel
       
       --    if selCount is 0 then my errMsg() det er alltid et finder window og det er desktop
       
       if selCount is 2 then
           set {fileA, fileB} to {item 1 of theSel, item 2 of theSel}
       else
           if selCount is greater than 3 then my errMsg()
           
           if (count its windows) is 1 or selCount is 0 then my errMsg()
           -- only the desktop window or no items in the selection, -we don't handle folders - yet?
           set fileA to item 1 of theSel
           if class of fileA is not document file then my errMsg()
           set fw1 to id of its Finder window 1
           tell its Finder window 2 to activate
           
           set theSel to (get selection) -- of Finder window 1
           
           set selCount to count theSel
           if selCount ≠ 1 then my errMsg()
           set fileB to item 1 of theSel
           if class of fileB is not document file then my errMsg()
           tell Finder window id fw1 to activate
           if contents of fileB is equal to contents of fileA then my errMsg()
       end if
       
       
       set {mustDecompileFileA, mustDecompileFileB} to {my classifyASfile(fileA), my classifyASfile(fileB)}
       -- there were something applescript a like so we will commence
       set shortNm to name of fileA
       set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "."}
       set shortNm to text item 1 of shortNm
       set AppleScript's text item delimiters to ""
       set shortNm to shortNm as text
       
       
       set theDir to do shell script "/usr/bin/mktemp -d -t " & quoted form of shortNm
       
       set tempFn1 to quoted form of (theDir & "/" & my createPathDenotingFileNameWitoutExt((fileA as alias as text)))
       set tempFn2 to quoted form of (theDir & "/" & my createPathDenotingFileNameWitoutExt((fileB as alias as text)))
       
       if mustDecompileFileA then
           my decompileAppleScriptTextForDiff((fileA as alias), tempFn1)
       else
           try
               do shell script "cp " & quoted form of POSIX path of (fileA as alias) & " " & tempFn1
           end try
       end if
       if mustDecompileFileB then
           my decompileAppleScriptTextForDiff((fileB as alias), tempFn2)
       else
           try
               do shell script "cp " & quoted form of POSIX path of (fileB as alias) & " " & tempFn2
           end try
       end if
   end tell
   -- make the differences show up in text wrangler!
   try
       set myres to (do shell script "/usr/bin/twdiff --ignore-spaces " & tempFn1 & " " & tempFn2)
       tell me
           activate
           display alert "AppleScript Diff: The files are alike!"
       end tell
   on error e number n
       tell application "TextWrangler"
           activate
       end tell
   end try
end run

on classifyASfile(aFileRef)
   tell application "Finder"
       if file type of aFileRef is "osas" then return true
   end tell
   set aFileRef to aFileRef as alias
   tell application "System Events"
       set ftype to type identifier of (get properties of item (aFileRef as text))
       if ftype is not "com.apple.traditional-mac-plain-text" then
           my errMsg()
       else
           return false
       end if
   end tell
end classifyASfile

on errMsg()
   beep
   tell me
       activate
       display dialog "You need to select two and only two two different Apple Script files in the frontmost Finder Window or one file in each of the two frontmost Finder windows in order to run this script.
"
with title "AppleScriptDiff" buttons {"Ok"} default button 1 with icon file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:Unsupported.icns")
       
       error number -128
   end tell
end errMsg

on decompileAppleScriptTextForDiff(fileAlias, qpxTempFileName) -- Thanks to oldmanegan
   
   local theSourceText, qfPoxPath
   set qfPoxPath to quoted form of POSIX path of (fileAlias)
   try
       fileAlias as alias
   on error e number n
       set bad to true
   end try
   try
       do shell script "/usr/bin/osadecompile " & qfPoxPath & "| /usr/bin/tr -d '\\000' >" & qpxTempFileName
   on error e number n
       tell me
           activate
           display alert "AppleScriptDiff: decompileAppleScriptTextForDiff()" & e & " : " & n
       end tell
       error number -128
   end try
end decompileAppleScriptTextForDiff

on createPathDenotingFileNameWitoutExt(hfSfileNameAsText)
   set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
   -- set hfsFilenameAsText to {""} & text items 2 thru -1 of hfsFilenameAsText
   -- Uses the line above instead of line under if you want to convert to unix alike filename.
   set hfSfileNameAsText to text items of hfSfileNameAsText
   set AppleScript's text item delimiters to "_"
   set hfSfileNameAsText to hfSfileNameAsText as text
   set AppleScript's text item delimiters to "."
   set hfSfileNameAsText to text item 1 of hfSfileNameAsText as text
   set AppleScript's text item delimiters to tids
   return hfSfileNameAsText
end createPathDenotingFileNameWitoutExt

Last edited by McUsr (2012-07-16 10:40:39 am)


Mercurial vcs is a joy to use for scripting.


Filed under: differences

Offline

 

#2 2010-08-03 08:21:14 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3201

Re: Show differences in two AppleScript files with TextWrangler

Would be fine if it was able to compare two scripts even if one or two of them are text ones (wxyz.appleScript).

These ones may be identified by the pair
file type : TEXT
creator type : ToyS

or by the type identifier : com.apple.traditional-mac-plain-text"

compiled script's type identifier is : "com.apple.applescript.script"

Yvan KOENIG (VALLAURIS, France) mardi 3 août 2010 15:21:05

Offline

 

#3 2010-08-03 10:59:52 am

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: Show differences in two AppleScript files with TextWrangler

Hello Yvan.

That was a good idea, which I implemented, I was going to, but since there was a request... smile

I will use this together with some scripts for using the RCS (included) version control system with AppleScript a tad later.

I also removed some errors due to the fact that i did forget to remove the references to my script object when I "flattened" it.

Edit:
I'll make another version for plain text files of any kind a little bit later, as this is as useful as this, and easier than putting the files into FileMerges trays.

Edit+I will come back soon and turn it into a general script, where a file is converted into text by its Uti, so that you can see differences in an rtf file and a word file for instance.

Last edited by McUsr (2010-08-03 11:47:44 am)


Mercurial vcs is a joy to use for scripting.


Filed under: AppleScript diff

Offline

 

#4 2010-08-04 07:17:32 am

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: Show differences in two AppleScript files with TextWrangler

Hello.

I have updated the Script to take files from the two frontmost finder windows. -A bit more practical.
I have also added an icon to the dialog which displays error messages. Please ensure that the hard drive name corresponds with yours. ("Macintosh Hd")


Mercurial vcs is a joy to use for scripting.


Filed under: diferences

Offline

 

#5 2012-07-16 03:40:37 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4424

Re: Show differences in two AppleScript files with TextWrangler

McUsr wrote:

I have also added an icon to the dialog which displays error messages. Please ensure that the hard drive name corresponds with yours. ("Macintosh Hd")


The 'path to' command can save users having to do that:

Applescript:

display dialog "You need to select two and only two two different Apple Script files in the frontmost Finder Window or one file in each of the two frontmost Finder windows in order to run this script.
"
with title "AppleScriptDiff" buttons {"Ok"} default button 1 with icon file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:Unsupported.icns")

Or, unofficially:

Applescript:

display dialog "You need to select two and only two two different Apple Script files in the frontmost Finder Window or one file in each of the two frontmost Finder windows in order to run this script.
"
with title "AppleScriptDiff" buttons {"Ok"} default button 1 with icon file ((path to "csrv" as text) & "CoreTypes.bundle:Contents:Resources:Unsupported.icns")


NG

Offline

 

#6 2012-07-16 10:35:46 am

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: Show differences in two AppleScript files with TextWrangler

Hello Nigel! smile

Thank you very much for pointing that out! I have fixed, I probably have some others here, but I'll take them when they show up, at least for now.

I tend to do it your way nowadays, it is so much more practical!

About the codes
Is there a place you can find all those "unofficial codes" I believe I have seen people calling application "syscve" for instance. and it would be good to have that knowledge, that is, if there is a compilation somewhere, or if they are all from a system doc.

Last edited by McUsr (2012-07-16 10:42:57 am)


Mercurial vcs is a joy to use for scripting.


Filed under: path to folder

Offline

 

#7 2012-07-16 11:44:23 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4424

Re: Show differences in two AppleScript files with TextWrangler

McUsr wrote:

Is there a place you can find all those "unofficial codes"


/System/Library/Frameworks/CoreServices.framework/Versions/A/
Frameworks/CarbonCore.framework/Versions/A/Headers/Folders.r

… but don't get carried away.

Edit: Path split into two lines to make it all visible in the forum window.

Last edited by Nigel Garvey (2012-07-16 11:50:55 am)


NG

Offline

 

#8 2012-07-16 02:52:10 pm

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: Show differences in two AppleScript files with TextWrangler

Thanks a whole lot! smile

I am not intending to use it, but it is good to be able to understand what is going on at times, when people has resorted to this practice.

My personal views on this is that the  codes should be avoided, if there exist other alternatives.

But there is sure many codes in there, that there aren't many alternatives too. big_smile Interesting!!!

Having said that;  those codes, that is one thing, raw events in code, a totally different one, but I guess it is sometimes necessary.

Last edited by McUsr (2012-07-16 02:57:40 pm)


Mercurial vcs is a joy to use for scripting.


Filed under: codes

Offline

 

#9 2012-07-16 07:55:31 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5178

Re: Show differences in two AppleScript files with TextWrangler

Nigel Garvey wrote:

Applescript:

display dialog "You need to select two and only two two different Apple Script files in the frontmost Finder Window or one file in each of the two frontmost Finder windows in order to run this script.
"
with title "AppleScriptDiff" buttons {"Ok"} default button 1 with icon file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:Unsupported.icns")


Or even:

Applescript:

display dialog "You need to select two and only two two different Apple Script files in the frontmost Finder Window or one file in each of the two frontmost Finder windows in order to run this script.
"
with title "AppleScriptDiff" buttons {"OK"} default button 1 with icon (path to resource "Unsupported.icns" in bundle ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle") as alias)


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#10 2012-07-16 09:47:15 pm

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: Show differences in two AppleScript files with TextWrangler

Hello! smile

There is something odd right there icon or icon file, sometimes one works but not the other, I guess that is when I have made a file reference to the icon image up front, I'll make a mental note about that!


Mercurial vcs is a joy to use for scripting.


Filed under: icon, icon file

Offline

 

#11 2012-07-17 03:39:08 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4424

Re: Show differences in two AppleScript files with TextWrangler

McUsr wrote:

There is something odd right there icon or icon file, sometimes one works but not the other, I guess that is when I have made a file reference to the icon image up front, I'll make a mental note about that!


Yes. The relevant labelled parameter of 'display dialog' is 'with icon'. The value of this parameter has to be an 'alias' or 'file' reference. In your original code (and my variant), the 'file' is in front of some code which produces an HFS text path, so the overall effect is a file specifier.

Shane coerces his path to alias instead, which I think is slighty more efficient "on the fly". This alias then becomes the 'in bundle' parameter of a 'path to resource' command, which in turn returns another alias. Putting 'file' in front of the result would cause an error.


NG

Offline

 

#12 2012-07-17 01:27:15 pm

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: Show differences in two AppleScript files with TextWrangler

Hello. smile

Applescript:

display dialog "You need to select two and only two two different Apple Script files in the frontmost Finder Window or one file in each of the two frontmost Finder windows in order to run this script.
"
with title "AppleScriptDiff" buttons {"OK"} default button 1 with icon (path to resource "Unsupported.icns" in bundle ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle") as alias)

Nigel Garvey wrote:

Shane coerces his path to alias instead, which I think is slighty more efficient "on the fly". This alias then becomes the 'in bundle' parameter of a 'path to resource' command, which in turn returns another alias. Putting 'file' in front of the result would cause an error


It is interesting to know that Shane's coercing is faster, and to be reminded of the in bundle paramter of the path to command.

And yes, the file keyword, is a qualifier for what comes after icon in the display dialog command. (That the file keyword doesn't work with a file reference is something to understand, that it doesn't work with the alias is not so intiuitive, but maybe it is only Finder that takes easy on such matters.)

Last edited by McUsr (2012-07-17 01:28:50 pm)


Mercurial vcs is a joy to use for scripting.


Filed under: coercing

Offline

 

#13 2012-07-17 02:07:03 pm

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4424

Re: Show differences in two AppleScript files with TextWrangler

McUsr wrote:

… and to be reminded of the in bundle paramter of the path to command.


It's actually the path to resource command. There's no in bundle parameter with path to.


NG

Offline

 

#14 2012-07-17 04:59:57 pm

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: Show differences in two AppleScript files with TextWrangler

Hello.

Nigel Garvey wrote:

It's actually the path to resource command. There's no in bundle parameter with path to.


I wonder, why is there an own path to resource command, other than the obvious, to state in your code that you are getting a resource?

Is there any differences from this to the normal path to command that I should be aware of, than merely the in bundle parameter?

Edit:

I see it is handy for getting into bundles, and that the directory parameter is taking a parameter relative to the resources folder of a bundle of an app.

Last edited by McUsr (2012-07-17 05:10:03 pm)


Mercurial vcs is a joy to use for scripting.


Filed under: path to

Offline

 

#15 2012-07-18 04:07:49 am

alastor933
Member
From:: Utrecht, NL
Registered: 2008-09-12
Posts: 544

Re: Show differences in two AppleScript files with TextWrangler

Um, looking at the dictionary entries I see that 'path to' either takes an application name, or some variant of that (like 'me' or 'it'), or a folder designation (not same as its name) from a predefined (and fixed!) list.

So you can use 'path to' on applications and (specific) folders, but not on other bundle types.
That's where 'path to resource' comes in, with 'in bundle' to plunder any bundle whatsoever, privileges permitting.

Anyway, that's my €0,02.

Last edited by alastor933 (2012-07-18 04:08:58 am)

Offline

 

#16 2012-07-22 12:27:01 am

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: Show differences in two AppleScript files with TextWrangler

Hello!

This horse is beaten to death, I know! big_smile

My final words is, that when it comes to at least icon resources then I prefer the a reference to file to an alias because then there isn't any alias to resolve during the awakening of the dialog. I don't know if this can be felt, or timed, as our cpu's performs several billions instructions per second, nowadays, and SSD disks are also around...

But at least, it feels faster, when you know that the icon file doesn't have to be resolved during the display of a dialog.

So my favorite for displaying icons in dialog boxes are:

Applescript:

set my infoIcon to a reference to file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:AlertNoteIcon.icns")

Last edited by McUsr (2012-07-22 12:30:46 am)


Mercurial vcs is a joy to use for scripting.

Offline

 

#17 2012-07-22 05:50:25 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4424

Re: Show differences in two AppleScript files with TextWrangler

McUsr wrote:

So my favorite for displaying icons in dialog boxes are:

Applescript:

set my infoIcon to a reference to file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:AlertNoteIcon.icns")


Yuk! I wish I hadn't looked at this this morning!  neutral

As expected:

Applescript:

alias ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:AlertNoteIcon.icns")
--> alias "MacBook Pro HD:System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:AlertNoteIcon.icns"

((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:AlertNoteIcon.icns") as alias
--> alias "MacBook Pro HD:System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:AlertNoteIcon.icns"

a reference to file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:AlertNoteIcon.icns")
--> file "MacBook Pro HD:System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:AlertNoteIcon.icns" of «script»

But (in Leopard and Snow Leopard):

Applescript:

file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:AlertNoteIcon.icns")
--> error "Can’t get file \"MacBook Pro HD:System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:AlertNoteIcon.icns\"."

But again:

Applescript:

read file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:AlertNoteIcon.icns") as data
--> «data rdat69636E73000063A249434E230000010800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FF800007FFF000… etc.

The above phenomena are true with any kind of file, not just system icons.

With regard to setting up and using file references, I haven't been able to find any reliable difference in speed between using 'file blah' and 'a reference to file blah'. But they're both definitely faster than 'blah as alias', which in turn is faster than 'alias blah'. My earlier assertion that a coercion to alias is more efficient than a run-time file specifier must have been confusion with the fact that it's faster than a run-time alias specifier. File specifiers are fastest, although they no longer appear to exist.  hmm


NG

Offline

 

#18 2012-07-22 06:40:30 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5178

Re: Show differences in two AppleScript files with TextWrangler

Nigel Garvey wrote:

With regard to setting up and using file references, I haven't been able to find any reliable difference in speed between using 'file blah' and 'a reference to file blah'. But they're both definitely faster than 'blah as alias', which in turn is faster than 'alias blah'. My earlier assertion that a coercion to alias is more efficient than a run-time file specifier must have been confusion with the fact that it's faster than a run-time alias specifier. File specifiers are fastest


I don't doubt you, but these days I think it's worth adding a rider about the OS used for testing -- as you're seeing, there have been changes under the hood on what constitutes a file.

although they no longer appear to exist.


I'm not sure if it's just a transition gone wrong or not. If you call, say, choose file name, the result appears as 'file "Blah:blah"', but its class is «class furl». It looks to me like «class furl» has been given the term file, but that the older «class file» still has it too.

OYOH, "as «class furl»" seems to work nicely...


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#19 2012-07-23 07:34:07 am

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: Show differences in two AppleScript files with TextWrangler

I just want to add that I was writing about feelings but it was in a script consisting of a little less than 2000 lines at the time being, from within Script Debugger in Debug mode.

I don't think I can't notice any difference anyway, when the script is running, though the file refrence, drags a little less resources. and furls are ok, as long as file references stay!

But then again, I like the screen updates to be as crisp as possible, so I will use the filereferences for icons anyway.

But you have to have rather quick reactions, to spot any difference, in this snippet! smile


Applescript:


set infoIcon to a reference to file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:AlertNoteIcon.icns")

set unsuppicon to (path to resource "Unsupported.icns" in bundle ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle") as alias)


tell application "SystemUIServer"
   activate
   
   display dialog "Hit Enter" with icon 1
   
   display dialog "You hit Enter" with icon infoIcon
   
   display dialog "Hit Enter" with icon 1
   
   display dialog "You hit Enter" with icon unsuppicon
end tell


Mercurial vcs is a joy to use for scripting.


Filed under: filereferences

Offline

 

#20 2012-07-23 11:27:29 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4424

Re: Show differences in two AppleScript files with TextWrangler

Shane Stanley wrote:

I'm not sure if it's just a transition gone wrong or not. If you call, say, choose file name, the result appears as 'file "Blah:blah"', but its class is «class furl». It looks to me like «class furl» has been given the term file, but that the older «class file» still has it too.

OYOH, "as «class furl»" seems to work nicely...


Interesting. Thanks for the insight.


NG

Offline

 

#21 2012-07-23 08:59:28 pm

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: Show differences in two AppleScript files with TextWrangler

Hello!


I came by this document on the net, from 1997.

I wonder if you know about any more updated resource on the subject matter?

I see code where people address System Events with "syscve" or similiar, and also sending «event Pcap»  I wonder, if this partuclar lore can be found somewhere, or is there just tid bits floating around?

Last edited by McUsr (2012-07-23 09:00:57 pm)


Mercurial vcs is a joy to use for scripting.


Filed under: lore

Offline

 

#22 2012-07-23 09:48:23 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5178

Re: Show differences in two AppleScript files with TextWrangler

McUsr wrote:

I wonder if you know about any more updated resource on the subject matter?


You can hunt through the header files, or just look at code in Script Debugger showing raw syntax. But of themselves, they're not particularly enlightening.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#23 2012-07-23 10:08:45 pm

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: Show differences in two AppleScript files with TextWrangler

Shane Stanley wrote:
McUsr wrote:

I wonder if you know about any more updated resource on the subject matter?


You can hunt through the header files, or just look at code in Script Debugger showing raw syntax. But of themselves, they're not particularly enlightening.


That is so true, about enlightening, and must I add interesting. But sometimes, there are gems to be found, like the trick by running a script to make something into a format that for example finder will take, with lists with  keywords and specifiers that  finder will understand, and accept. Or the trick by throwing an error to get read access to a datstructure, that are otherwise consealed, by reading the error string.

Sometimes, things can only be accomplished by a trick, and then it is good to know where to look for it!

And sometimes, you want sheer speed, not that it is neccessary at all times, but when the system is bogged down, then it helps, both to the robustness, and the responsetimes.

That is the only thing I can see as a liable excuse for using the more arcane language constructs.

By the way I figured out by some googling, that the alternative application id, was  the applications creator type, that it can be used as an alternative for the bundle identifier

On my way I also learned that the bundle identifier of apps may vary with whether they are bought in the Appstore or not, and that holds for the creator type as well. big_smile

I found that part in http://forums.omnigroup.com/showthread.php?p=98911

Last edited by McUsr (2012-07-23 10:23:45 pm)


Mercurial vcs is a joy to use for scripting.


Filed under: creator type

Offline

 

#24 2013-11-20 10:03:12 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Show differences in two AppleScript files with TextWrangler

Hello.

I have updated the script for Mavericks, TextWranglers path to twdiff has changed, I have also removed references to my  "coreLibraryLoaderServer", as with some new technology, and pretty much before that, it was obsolete. Lots of work to make it work, and it still does! But not worth the effort, in any sense. big_smile

The script still decompiles two applescripts, and puts it up into TextWrangler, so you'll need TextWrangler for this one, and the command line tools installed.

P.S If you had the commandline tools installed before you installed Mavericks over your old operating system, then you may have to reinstall them. I had to at least. If this script doesn't seem to work, then please visit a terminal window and execute the command which twdiff.

Applescript:



-- © McUsr 2010 and put in Public Domain see: macscripter.net/viewtopic.php?id=33758 (post #26) for reference and terms of use.

(*
    Copyright © 2010 - 2015 McUsr: Fixed a bug in the classifyASfile() handler.
    You may not post this as a work on your own somewhere, including paper.
*)


on run
   tell application "Finder"
       activate
       set theSel to (get selection)
       
       set selCount to count theSel
       
       
       if selCount is 2 then
           set {fileA, fileB} to {item 1 of theSel, item 2 of theSel}
       else
           if selCount is greater than 3 then my errMsg()
           
           if (count its windows) is 1 or selCount is 0 then my errMsg()
           -- only the desktop window or no items in the selection, -we don't handle folders - yet?
           set fileA to item 1 of theSel
           
           if class of fileA is not document file and class of fileA is not application file then my errMsg()
           set fw1 to a reference to its Finder window 1
           tell its Finder window 2 to activate
           
           set theSel to (get selection) -- of Finder window 2
           
           set selCount to count theSel
           if selCount ≠ 1 then my errMsg()
           set fileB to item 1 of theSel
           if class of fileB is not document file and class of fileB is not application file then my errMsg()
           tell fw1 to activate
           if contents of fileB is equal to contents of fileA then my errMsg()
       end if
       
       
       set {mustDecompileFileA, mustDecompileFileB} to {my classifyASfile(fileA), my classifyASfile(fileB)}
       -- there were something applescript a like so we will commence
       set shortNm to name of fileA
       set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "."}
       set shortNm to text item 1 of shortNm
       set AppleScript's text item delimiters to ""
       set shortNm to shortNm as text
       
       
       set theDir to do shell script "/usr/bin/mktemp -d -t " & quoted form of shortNm
       
       set tempFn1 to quoted form of (theDir & "/" & my createPathDenotingFileNameWitoutExt((fileA as alias as text)))
       set tempFn2 to quoted form of (theDir & "/" & my createPathDenotingFileNameWitoutExt((fileB as alias as text)))
       
       if mustDecompileFileA then
           my decompileAppleScriptTextForDiff((fileA as alias), tempFn1)
       else
           try
               do shell script "cp " & quoted form of POSIX path of (fileA as alias) & " " & tempFn1
           end try
       end if
       if mustDecompileFileB then
           my decompileAppleScriptTextForDiff((fileB as alias), tempFn2)
       else
           try
               do shell script "cp " & quoted form of POSIX path of (fileB as alias) & " " & tempFn2
           end try
       end if
   end tell
   -- make the differences show up in text wrangler!
   try
       set myres to (do shell script "/usr/local/bin/twdiff --ignore-spaces " & tempFn1 & " " & tempFn2)
       tell (path to frontmost application as text)
           display dialog "The files are alike!" with title "AppleScriptDiff" buttons {"Ok"} default button 1
       end tell
   on error e number n
       tell application "TextWrangler"
           activate
       end tell
   end try
end run

on classifyASfile(aFileRef)
   tell application "Finder"
       if file type of aFileRef is "osas" then return true
   end tell
   set aFileRef to aFileRef as alias
   
   tell application id "sevs"
       set ftype to type identifier of (get properties of item (aFileRef as text))
       if ftype contains "com.apple.applescript.script" then
           -- works for "com.apple.applescript.script" and "com.apple.applescript.script-bundle"
           return true
       else
           return false
       end if
   end tell
end classifyASfile


on errMsg()
   beep
   tell (path to frontmost application as text)
       display dialog "You need to select two and only two two different Apple Script files in the frontmost Finder Window or one file in each of the two frontmost Finder windows in order to run this script. If you are trying to get diffs of applets those need to have the original filepropeties as when the applet was saved in the editor in order for the script to run properly.
"
with title "AppleScriptDiff" buttons {"Ok"} default button 1
   end tell
   error number -128
end errMsg

on decompileAppleScriptTextForDiff(fileAlias, qpxTempFileName) -- Thanks to oldmanegan
   
   local theSourceText, qfPoxPath
   set qfPoxPath to quoted form of POSIX path of (fileAlias)
   try
       fileAlias as alias
   on error e number n
       set bad to true
   end try
   try
       beep
       do shell script "/usr/bin/osadecompile " & qfPoxPath & "| /usr/bin/tr -d '\\000' >" & qpxTempFileName
   on error e number n
       tell application (path to frontmost application as text)
           display dialog "AppleScriptDiff: decompileAppleScriptTextForDiff()" & e & " : " & n with title "AppleScriptDiff" buttons {"Ok"} default button 1
       end tell
       error number -128
   end try
end decompileAppleScriptTextForDiff

on createPathDenotingFileNameWitoutExt(hfSfileNameAsText)
   set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
   -- set hfsFilenameAsText to {""} & text items 2 thru -1 of hfsFilenameAsText
   -- Uses the line above instead of line under if you want to convert to unix alike filename.
   set hfSfileNameAsText to text items of hfSfileNameAsText
   set AppleScript's text item delimiters to "_"
   set hfSfileNameAsText to hfSfileNameAsText as text
   set AppleScript's text item delimiters to "."
   set hfSfileNameAsText to text items 1 thru -2 of hfSfileNameAsText as text
   set AppleScript's text item delimiters to tids
   return hfSfileNameAsText
end createPathDenotingFileNameWitoutExt

Last edited by McUsrII (2015-04-07 10:52:24 am)


Filed under: textwrangler, TwDiff

Offline

 

#25 2013-11-26 11:08:10 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Show differences in two AppleScript files with TextWrangler

Hello.

I removed a bug I had entered, in the handler that created a filename denoting the path of the original filename.

It is now fixed.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)