Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
This perl code compiles and runs an apple mac app that decompiles and prints its own applescript source code:
perl -Mautodie -we '$app="ApplePerlQuine\@perlmonks.org.app";die"not a +pple mac"unless${^O}eq"darwin";open$f,"|-","osacompile -o $app";print +$f qq~set myPATH to path to me as string\nset myPATH to myPATH & "Con +tents:Resources:Scripts:main.scpt"\nset myPATH to do shell script"ech +o " & myPATH & " | tr : / | sed -E \x27s/Macintosh HD//\x27"\ndisplay + dialog (do shell script ("osadecompile " & myPATH)) with title "$app +" buttons {"Use Perl!"} default button 1\n~;close$f;system("open $app +")'

Easier to read:
perl -Mautodie -we '$app="ApplePerlQuine\@perlmonks.org.app";
die"not apple mac"unless${^O}eq"darwin";
open$f,"|-","osacompile -o $app";
print$f qq~

set myPATH to path to me as string\n
set myPATH to myPATH & "Contents:Resources:Scripts:main.scpt"\n
set myPATH to do shell script"echo " & myPATH & " | tr : / | sed -E \x27s/Macintosh HD//\x27"\n
display dialog (do shell script ("osadecompile " & myPATH)) with title "$app" buttons {"Use Perl!"} default button 1\n

~;
close$f;
system("open $app")'

Easier to understand:

1. Perl setup:
    
    perl -Mautodie -we '$app = "ApplePerlQuine\@perlmonks.org.app";
    die "not apple mac" unless ${^O} eq "darwin";
    
    
2. Open pipe to applescript compiler and print:
    
    open $f, "|-", "osacompile -o $app"; print$f qq~
    
    
3. Set applescript variable to the app path:
    
    set myPATH to path to me as string\n
    
    
4. Append path of compiled source (inside the app):
    
    set myPATH to myPATH & "Contents:Resources:Scripts:main.scpt"\n
    
    
5. Use shell to manipulate the path:
    
    set myPATH to do shell script"
    
    
6. Change applescript variable with tr and sed:
    
    echo " & myPATH & " | tr : / | sed -E \x27s/Macintosh HD//\x27"\n
    
    
7. Decompile app and display source code:
    
    display dialog (do shell script ("osadecompile " & myPATH)) with title "$app" buttons {"Use Perl!"} default button 1\n
    
    
8. Back to perl, end print, close pipe, open app:
    
    ~; close$f; system("open $app")'
    
    
Summary: lines 1-2 and 8 use perl to write the app with applescript in lines 3-7.

As a script:

#!/usr/bin/perl use strict; use warnings; use autodie; die "not apple mac" unless ${^O} eq "darwin"; my $app = "ApplePerlQuine\@perlmonks.org.app"; open my $f, "|-", "osacompile -o $app"; print $f qq~set myPATH to path to me as string set myPATH to myPATH & "Contents:Resources:Scripts:main.scpt" set myPATH to do shell script "echo " & myPATH & " | tr : / | sed -E \ +x27s/Macintosh HD//\x27" display dialog (do shell script ("osadecompile " & myPATH)) with title + "$app" buttons {"Use Perl!"} default button 1\n~; close $f; system("open $app");


This one prints itself entirely, including the perl:

perl -Mautodie -we '$app=qq(ApplePerlQuine\@perlmonks.org.app);die"not + apple mac"unless${^O}eq"darwin";open$f,qq(|-),qq(osacompile -o $app) +;print$f qq(set myPATH to path to me as string\nset myPATH to myPATH +& "Contents:Resources:Scripts:main.scpt"\nset myPATH to do shell scri +pt"echo " & myPATH & " | tr : / | sed -E \x27s/Macintosh HD//\x27"\nd +isplay dialog (\"perl -Mautodie -we \x27\x24app=qq(ApplePerlQuine\134 +\134\100perlmonks.org.app);\nopen\x24f,qq(|-),qq(osacompile -o \x24ap +p);\nprint\x24f qq\(\" & do shell script ("osadecompile " & myPATH)) +& "\);close\x24;system\(\x27\x27open \x24app\x27\x27\)" with title "$ +app" buttons {"Use Perl!"} default button 1\n\(* This is an ASCII rep +resentation of the Perl source used to make this app. It will not cut + and paste because of hex and octal tricks. See perlmonks.org/?node=1 +216984 for details. *\));close$f;system("open $app")'
STOP REINVENTING WHEELS, START BUILDING SPACE ROCKETS!CPAN

In reply to Apple Perl Quine by usemodperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (10)
    As of 2018-10-19 09:40 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      When I need money for a bigger acquisition, I usually ...














      Results (107 votes). Check out past polls.

      Notices?