Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

15
LINES

< > BotCompany Repo | #1026393 // addAssociationToMimeAppsList

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2724L/18K).

sS addAssociationToMimeAppsList(S key, S value) {
  File f = userDir(".local/share/applications/mimeapps.list");
  if (!fileExists(f)) ret f2s(f) + " not found";
  LS l = lines(loadTextFile(f));
  int i = indexOfTrim(l, "[Default Applications]");
  if (i < 0) ret "[Default Applications] not found in " + f2s(f);
  
  int j = indexOfStartingWith(l, key + "=");
  if (j >= 0) ret "Association already there: " + l.get(j);
  
  S line = key + "=" + value;
  l.add(i+1, line);
  saveTextFile(f, lines(l));
  ret "Added " + quote(line) + " to " + f2s(f);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1026393
Snippet name: addAssociationToMimeAppsList
Eternal ID of this version: #1026393/5
Text MD5: 528d92c787a6b5485d19aef6a9413362
Transpilation MD5: 521124f885387d3077f0f9041e4aa8c3
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-01-02 13:28:06
Source code size: 566 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 143 / 225
Version history: 4 change(s)
Referenced in: [show references]