2009-10-15 4 views
1

Pour des raisons que seuls les développeurs peuvent comprendre, Firefox créera et ouvrira des fichiers .url sur Windows et des fichiers .webloc sur OS X mais ne permettra pas à la version Windows de Firefox de Ouvrez les fichiers .webloc ou la version OS X de Firefox pour ouvrir les fichiers .url. (Les fichiers .url s'ouvrent dans Safari mais ce n'est pas assez bon pour des raisons qui ne valent pas la peine d'entrer ici.) Dans le cadre de mes efforts pour utiliser n'importe quel type de fichier, j'écris un applescript pour ouvrir les fichiers .url sur OS X Firefox.Applescript pour ouvrir les fichiers .url sur OS X Firefox

on open the_droppings 
    set filePath to the_droppings 

    set fp to open for access filePath 
    set fileContents to read fp 
    close access fp 

    set secondLine to paragraph 2 of fileContents 

    set tid to AppleScript's text item delimiters 
    set AppleScript's text item delimiters to "=" 
    set URLstring to last text item of secondLine 
    set AppleScript's text item delimiters to tid 

    tell application "Firefox" 
     activate 
     OpenURL URLstring 
    end tell 
end open 

Je pensais que cela fonctionnerait, mais dans la dernière ligne 3 il est dit « fin prévue de la ligne, etc., mais trouvé identifiant. » Pourquoi est-ce?

EDIT réponse de Sakra ci-dessous, mais travaille surtout sur les pauses contenant urls « = » tels que: http://example.com?foo=a&bar=z

+0

Pour voir comment ouvrir les fichiers de Windows dans OS Fichiers X et OS X.webloc sous Windows: http://superuser.com/questions/54111/cross-platform-bookmark-files – Dinah

Répondre

2

Firefox ne semble pas figurer du tout un dictionnaire AppleScript. Par conséquent, le terme OpenURL dans l'instruction tell app "Firefox" est interprété comme un identifiant AppleScript et non comme une commande AppleScript. Deux identifiants AppleScript dans une ligne entraînent une erreur de syntaxe.

En tant que travail autour de vous pouvez utiliser la commande shell open en combinaison avec la commande standard AppleScript do shell script:

on open the_droppings 

    set filePath to the_droppings 

    set fileContents to read filePath 

    set theOffset to offset of "URL=" in fileContents 
    set URLstring to text (theOffset + 4) through -1 of fileContents 

    do shell script "/usr/bin/open -a Firefox.app " & quoted form of URLstring 
end open 
+0

Malheureusement ce script ne fonctionne pas pour moi car il prend en charge la partie IDList du fichier url dans l'URL entrée dans Firefox. Peut-être quelque chose qui a été introduit dans Windows Vista ou 7, mais c'est la raison pour laquelle j'ai fait une nouvelle version du script. – laarsk

0

EDIT: télécharger mon script dans une application ici: http://www.mediafire.com/?v77bv9gl9e7oj40

Cela fonctionne même mieux:

on open the_droppings 
    set filePath to the_droppings 
    set fileContents to read filePath 

    set theOffsetA to offset of "URL=" in fileContents 
    set theOffsetB to offset of "IDList=" in fileContents 
    set URLstring to text (theOffsetA + 4) through (theOffsetB - 3) of fileContents 

    do shell script "/usr/bin/open -a Firefox.app " & quoted form of URLstring 
end open 

Il lit l'URL = ligne à la ligne suivante (IDList) moins 3 étapes (pour ignorer e le \ r \ n) et l'envoie à firefox. Fonctionne comme un charme pour moi. J'ai cependant vu des fichiers url avec une disposition bizarre (exemple: http://forums.mozillazine.org/viewtopic.php?p=2619487), dont je ne suis pas sûr si cela fonctionnerait. Mais j'ai vérifié beaucoup de mes dossiers d'url et ils n'ont pas cela, ainsi au moins cela fonctionne bien pour moi. Faites-moi savoir si vous rencontrez des problèmes avec ce script. Pour l'instant je le mets en application par défaut pour ouvrir les fichiers URL, au lieu de Safari!

Pour pouvoir d'ouvrir des fichiers d'URL avec un fichier AppleScript, il doit avoir les doctypes appropriés et un ensemble d'identifiant dans son plist, comme ceci:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
    <key>CFBundleAllowMixedLocalizations</key> 
    <true/> 
    <key>CFBundleDevelopmentRegion</key> 
    <string>English</string> 
    <key>CFBundleDocumentTypes</key> 
    <array> 
     <dict> 
      <key>CFBundleTypeExtensions</key> 
      <array> 
       <string>url</string> 
      </array> 
      <key>CFBundleTypeIconFile</key> 
      <string>document.icns</string> 
      <key>CFBundleTypeName</key> 
      <string>URL File</string> 
      <key>CFBundleTypeOSTypes</key> 
      <array> 
       <string>URL</string> 
      </array> 
      <key>CFBundleTypeRole</key> 
      <string>Viewer</string> 
     </dict> 
    </array> 
    <key>CFBundleExecutable</key> 
    <string>droplet</string> 
    <key>CFBundleIdentifier</key> 
    <string>filehandler.url.mozilla.firefox</string> 
    <key>CFBundleIconFile</key> 
    <string>droplet</string> 
    <key>CFBundleInfoDictionaryVersion</key> 
    <string>6.0</string> 
    <key>CFBundleName</key> 
    <string>FirefoxURLHandler</string> 
    <key>CFBundlePackageType</key> 
    <string>APPL</string> 
    <key>CFBundleSignature</key> 
    <string>dplt</string> 
    <key>LSMinimumSystemVersionByArchitecture</key> 
    <dict> 
     <key>x86_64</key> 
     <string>10.6</string> 
    </dict> 
</dict> 
</plist>