Script to Add your Map routes to Notes.App

Discussion in 'iOS Jailbreak & Cydia' started by flash84x, Oct 25, 2007.

  1. flash84x

    flash84x New Member

    Joined:
    Sep 18, 2007
    Messages:
    103
    Likes Received:
    0
    Ok I just finished putting this together and it seems to work fairly well for me.

    The idea is that you can create a route in Maps.app and then save the text version of that route as a Note in Notes.app, you can then use the directions anytime you need them and even E-mail them to a friend.

    Disclaimer: This is NOT an app, it is merely shell and PHP script, I do not know how to write Apps at this time nor was I able to get the dev environment installed on my Linux box (might be picking up a Mac Mini this weekend to start developing apps on and just playing with OS X 10.5). So with that said, you should be somewhat familiar with VTerm (or Tapp, my tapp doesnt work?).

    Requirements:

    Erica's Utilities
    VTerm (or anything that lets you execute shell scripts)
    PHP
    Notes from iPhone
    Maps from iPhone

    "Installation":

    1. Download the PHP script by copying it from the source window or downloading from the attachments and put it on your iPod as /var/root/map2note.php
    2. Download the shell script and also place it under /var/root/route2note.sh (you can name this whatever you want though)
    3. chmod 755 route2note.sh

    How to use:

    1. Open Maps and create a route
    2. If you do not use the route feature it is possible you do not have the necessary Route.plist file, to obtain it, create a Route, press Home, open Calculator (any app), and press Home. It should have written Route.plist under /var/root/Library/Maps/Route.plist if it was not already there
    3. Execute route2note.sh
    4. Open Notes and see that your route was saved!

    If you have troubles feel free to post replies here, I hope this is useful to some people and I also hope that maybe some day we can convert it to an app or actually add a button to the Maps.app that does this.


    Source Code:

    map2note.php
    PHP:
    <?
    // load file that plist2txt creates
    if(file_exists('Library/Maps/Route.txt'))
    {
        
    $xml simplexml_load_file('Library/Maps/Route.txt');
    }
    else
    {
        exit(
    'Failed to open Route.txt');
    }

    // insert into Note
    $timeStamp time() - mktime(17,0,0,12,31,2000);

    echo 
    "INSERT INTO Note VALUES('".$timeStamp."','".sqlite_escape_string($xml->dict[0]->dict[0]->string[2]) . " to " sqlite_escape_string($xml->dict[0]->dict[0]->string[0]) ."','Distance: " sqlite_escape_string($xml->dict[0]->dict[0]->string[1]) ."');\n";

    // insert into note_bodies
    echo "INSERT INTO note_bodies VALUES((SELECT IFNULL(MAX(note_id)+1,1) FROM note_bodies),'";
    echo 
    sqlite_escape_string($xml->dict[0]->dict[0]->string[2]) . " to " sqlite_escape_string($xml->dict[0]->dict[0]->string[0]);
    echo 
    "<div>Distance: " sqlite_escape_string($xml->dict[0]->dict[0]->string[1]) . "</div>";
    echo 
    "<div>Time: " sqlite_escape_string($xml->dict[0]->dict[0]->string[3]) . "</div>";
    echo 
    "<div><br class=\"webkit-block-placeholder\"></div>";

    foreach(
    $xml->dict[0]->dict[0]->{'array'}[1]->dict as $value)
    {
        echo 
    "<div>" sqlite_escape_string($value->string) ."</div>";
        echo 
    "<div><br class=\"webkit-block-placeholder\"></div>";
    }

    echo 
    "');";

    ?>
    route2note.sh
    Code:
    export PATH=$PATH:/opt/iphone/bin
    plist2txt Library/Maps/Route.plist 
    php map2note.php > /temp/map2note.sql
    sqlite3 Library/Notes/notes.db < /temp/map2note.sql
    echo 1>&2 Route added to Notes

    You can see from the code how this works, all it does is converts the binary Route.plist to text, passes that text through a customized XML parser written in PHP that creates SQLite INSERT queries and passes those to the notes database. Very simple concept!

    Attached Files:

  2. nperkal

    nperkal New Member

    Joined:
    Oct 21, 2007
    Messages:
    10
    Likes Received:
    0
    Thanx, this is exactly what I'm looking for but I can't seem to get it to work. When I execute it says file not found. Please advise.
  3. flash84x

    flash84x New Member

    Joined:
    Sep 18, 2007
    Messages:
    103
    Likes Received:
    0
    Glad to see that someone could benefit from this, there were some updates that needed to be made since Erica added the full blown putil command rather than just plist2txt (thx erica!) so here are the new files, you can chose to just update the shell script and uncomment the specified line or you can do both, id recommend both, i also attached a zip file with both files

    let me know if you still cannot get it to work with this updates, also be sure that you have added /var/root/bin to your path in order to utilize ericas utilities, if you receive errors like plutil not found or sqlite3 not file this is likely the issue

    Code:
    export PATH=$PATH:/opt/iphone/bin
    plutil -c xml1 Library/Maps/Route.plist
    # uncomment following line if you dont want to update php file
    # mv Library/Maps/Route.plist Library/Maps/Route.txt 
    php map2note.php > /temp/map2note.sql
    sqlite3 Library/Notes/notes.db < /temp/map2note.sql
    echo 1>&2 Route added to Notes
    
    PHP:
    <?
    // load file that plist2txt creates
    if(file_exists('Library/Maps/Route.plist'))
    {
        
    $xml simplexml_load_file('Library/Maps/Route.plist');
    }
    else
    {
        exit(
    'Failed to open Route.plist');
    }

    // insert into Note
    $timeStamp time() - mktime(17,0,0,12,31,2000);

    echo 
    "INSERT INTO Note VALUES('".$timeStamp."','".sqlite_escape_string($xml->dict[0]->dict[0]->string[2]) . " to " sqlite_escape_string($xml->dict[0]->dict[0]->string[0]) ."','Distance: " sqlite_escape_string($xml->dict[0]->dict[0]->string[1]) ."');\n

    "
    ;

    // insert into note_bodies
    echo "INSERT INTO note_bodies VALUES((SELECT IFNULL(MAX(note_id)+1,1) FROM note_bodies),'";
    echo 
    sqlite_escape_string($xml->dict[0]->dict[0]->string[2]) . " to " sqlite_escape_string($xml->dict[0]->dict[0]->string[0]);
    echo 
    "<div>Distance: " sqlite_escape_string($xml->dict[0]->dict[0]->string[1]) . "</div>";
    echo 
    "<div>Time: " sqlite_escape_string($xml->dict[0]->dict[0]->string[3]) . "</div>";
    echo 
    "<div><br class=\"webkit-block-placeholder\"></div>";

    foreach(
    $xml->dict[0]->dict[0]->{'array'}[1]->dict as $value)
    {
        echo 
    "<div>" sqlite_escape_string($value->string) ."</div>";
        echo 
    "<div><br class=\"webkit-block-placeholder\"></div>";
    }

    echo 
    "');";

    ?>

    Attached Files:

  4. nperkal

    nperkal New Member

    Joined:
    Oct 21, 2007
    Messages:
    10
    Likes Received:
    0
    You can't imagine how useful this program can be for me! Thanks for creating it. It still doesn't work with the new files. I get "plutil not found " and I do have the putil command in the 'bin' folder. I open up vterm and I type 'sh route2note.sh' and enter. Am I doing something wrong?? I need this so badly cuz I need to save a few routes! Thanx for replying so quickly! Could it be that your code was written for the iphone and not for the touch?? I have a touch version 1.1.2
  5. flash84x

    flash84x New Member

    Joined:
    Sep 18, 2007
    Messages:
    103
    Likes Received:
    0
    I actually have a touch that i programmed it for, no iphone so thats not an issue, i am on 1.1.1 so i am not sure if thats the issue... but if it is complaining about plutil not found it sounds like its not in your 'path'

    punch in the following in term or through ssh, however you want

    Code:
    echo export PATH=$PATH:/var/root/bin >> /var/root/.profile
    and then try again, to execute the script just do

    Code:
    ./route2note.sh
    oh and you're welcome, i needed this myself one time but havent needed it since

    Please Register or Log in to view images

  6. Mint-Berry Crunch

    Mint-Berry Crunch Member

    Joined:
    Sep 19, 2007
    Messages:
    776
    Likes Received:
    7
    Device:
    iPhone 6 Plus
    this is what it says:
    # ./route2note.sh
    ./route2note.sh:export:1: not an identifier: -c
    ./route2note.sh:2: no such file or directory: /temp/map2note.sql^Msqlite3
  7. nperkal

    nperkal New Member

    Joined:
    Oct 21, 2007
    Messages:
    10
    Likes Received:
    0
    I still get the Putil problem after typing that all in. Any quick suggestions? I'm leaving tonight!!
    now I'm not getting that error but its giving me file not found. When I get home I'll post the exact message.
  8. flash84x

    flash84x New Member

    Joined:
    Sep 18, 2007
    Messages:
    103
    Likes Received:
    0
    if the export is failing it sounds like you dont have php installed, look for it under development in the installer


    try this route2note.sh instead

    Code:
    export PATH=$PATH:/opt/iphone/bin:/var/root/bin
    plutil -c xml1 Library/Maps/Route.plist
    # uncomment following line if you dont want to update php file
    # mv Library/Maps/Route.plist Library/Maps/Route.txt 
    php map2note.php > /temp/map2note.sql
    sqlite3 Library/Notes/notes.db < /temp/map2note.sql
    echo 1>&2 Route added to Notes
    
  9. nperkal

    nperkal New Member

    Joined:
    Oct 21, 2007
    Messages:
    10
    Likes Received:
    0
    Thanx! Can you post it in a zip so that I can download it? I'd be very grateful!
  10. flash84x

    flash84x New Member

    Joined:
    Sep 18, 2007
    Messages:
    103
    Likes Received:
    0
    heh, checked the forums rigth after you posted

    here

    Attached Files:

Share This Page